Flutter 从 DropDropdownButton 中删除底部下划线

Ros*_*oss 8 flutter

我有一个位于我的应用栏中的下拉菜单。然而,它似乎有一个带下划线的默认值。颤振文档说默认为 0.0,但事实并非如此,我可以看到下划线。如何删除此下划线。

return Container(
  decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.all(Radius.circular(30)),
  ),
  margin: EdgeInsets.all(10.0),
  padding: EdgeInsets.all(5.0),
  width: MediaQuery.of(context).size.width * 0.30,
  child: Center(
    child: DropdownButton(
      items: _dropdownValues.map((value) => DropdownMenuItem(child: Text(value), value: value)).toList(),
        onChanged: (String value) {
          setState(() {
            _currentlySelected = value;
          });
        },
      isExpanded: false,
      value: _currentlySelected,
    )
  )
); 
Run Code Online (Sandbox Code Playgroud)

设计:

在此处输入图片说明

Ros*_*oss 31

我设法找到了答案。Flutter 非常有DropdownButtonHideUnderline帮助。我只是包裹DropdownButtonDropdownButtonHideUnderline.

代码:

return Container(
    decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(30)),
    ),
    margin: EdgeInsets.all(10.0),
    padding: EdgeInsets.all(5.0),
    width: MediaQuery.of(context).size.width * 0.30,
    child: Center(
        child: DropdownButtonHideUnderline(
            child: DropdownButton(
                items: _dropdownValues.map((value) => DropdownMenuItem(child: Text(value), value: value)).toList(),
                onChanged: (String value) {
                setState(() {
                    _currentlySelected = value;
                });
                },
                isExpanded: false,
                value: _currentlySelected,
            )
        )
    )
);
Run Code Online (Sandbox Code Playgroud)


Rya*_*nNa 9

另一种选择是使用下划线构造函数DropdownButton并将颜色设置为透明。

underline: Container(color: Colors.transparent),
Run Code Online (Sandbox Code Playgroud)

在你的情况下:

child: DropdownButton(
    items: _dropdownValues.map((value) => DropdownMenuItem(child: Text(value), value: value)).toList(),
    onChanged: (String value) {
    setState(() {
        _currentlySelected = value;
    });
    },
    isExpanded: false,
    underline: Container(color: Colors.transparent),
    value: _currentlySelected,
)
Run Code Online (Sandbox Code Playgroud)