Flutter从DropDropdownButton删除底部的下划线

标签 flutter

我的应用栏中有一个下拉菜单。但是,它似乎默认带有下划线。 flutter docs表示默认情况下为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,
    )
  )
); 

设计:

enter image description here

最佳答案

我设法找到答案。 Flutter的DropdownButtonHideUnderline非常有用。我只是将DropdownButton包装在DropdownButtonHideUnderline中。

代码:

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,
            )
        )
    )
);

关于Flutter从DropDropdownButton删除底部的下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57435480/

相关文章:

Flutter path_provider 和 sdk 版本不匹配

dart - 迭代 flutter map 中的元素

flutter - 如何修复 flutter 上的 "A RenderFlex overflowed by Infinity pixels on the bottom."错误?

dart - 如何仅在按下按钮时调用方法?

flutter - CustomPainter - shouldRepaint 值得吗?

android-studio - Flutter 和 Android Studio 中的内存不足错误

Flutter setState 预期有 3 个位置参数,但发现 1 个错误

flutter - 未找到设置为参数 "assets/background.png"的文件 "image"。 pub 已完成,退出代码为 1

Flutter 如何模拟对 rootBundle.loadString(...) 的调用,然后重置模拟的行为?

flutter - Flutter-如何根据父级宽度放置动态图 block 并包装到下一行