Flutter - ThemeData 上的样式 DropdownButton 和 DropdownMenu 不起作用

问题描述 投票:0回答:1

我只想使用

AlertDialog
ThemeData
内所有下拉菜单的颜色设置为白色。我想我可以从
ThemeData.dropdownMenuTheme
开始做到这一点。但不幸的是到目前为止还没有任何效果。

这是

ThemeData
部分。

class Env{

  static ThemeData theme = ThemeData(
    dropdownMenuTheme : DropdownMenuThemeData(
      textStyle : TextStyle(
        color : Colors.white
      ),
      menuStyle : MenuStyle(
        backgroundColor: MaterialStatePropertyAll<Color>(Colors.blue),
      ),
      inputDecorationTheme : InputDecorationTheme(
        labelStyle : TextStyle(
          color : Colors.white
        ),
        enabledBorder : UnderlineInputBorder(
          borderSide : BorderSide(
            color : Colors.white
          ),
        ),
        focusedBorder : UnderlineInputBorder(
          borderSide : BorderSide(
            color : Colors.white
          ),
        ),
      ),
    )
  )
}

这是

showDialog
的简化代码。

showDialog(
  context : context,
  builder : (BuildContext context) {
    return StatefulBuilder(builder : (BuildContext context, Function setState){
       return AlertDialog(
          title : Text('...'),
          content : SingleChildScrollView(child : Column(
             crossAxisAlignment : CrossAxisAlignment.start,
             children : [Row(children : [
                DropdownButton<int>(
                   value : value,
                   items : [for(int i = 0; i < values.length; i++) DropdownMenuItem(
                      value : i, child : Text(values[i]),
                   )],
                )
             ])]
          )),
       );
    })
  }
);

这就是我将

theme
设置为
MaterialApp
的方法。

MaterialApp(theme : Env.theme, home : scaffold);

我错过了什么?

flutter
1个回答
0
投票

根据您的评论:

默认情况下,我有灰色下划线和灰色图标按钮。我想要白色的

  1. 要删除下划线,请使用
    DropdownButtonHideUnderline
  2. 下拉菜单有一个
    icon
    字段,您可以设置它的颜色:

代码

  DropdownButtonHideUnderline(
      child: DropdownButton(
      icon: Icon(
      Icons.arrow_drop_down,
      color: Colors.green, // <-- your color. E.g, white
),
   value: value,

结果:

© www.soinside.com 2019 - 2024. All rights reserved.