如何更改DropdownButton的图标颜色?扑

Kor*_*enz 3 dropdown flutter

在Flutter中,我试图将DropdownButton的图标(向下箭头图标)的颜色更改为白色。

我尝试在没有帮助的情况下使用style属性。文本颜色变为白色,但图标仍为默认的灰色。

DropdownButton(
         style: TextStyle(color: Colors.white, decorationColor: 
             Colors.white),
         items: this.items,
         value: null,
         hint: Text(SaveOptions[_saveOption], style: TextStyle(color: 
             Colors.white)),
         onChanged: (selectedOption) {
           setState(() {
             _saveOption = selectedOption;
           });
         })
Run Code Online (Sandbox Code Playgroud)

如何将箭头图标的颜色更改为白色?

Alv*_*ban 11

您可以使用的字段iconEnabledColor,并iconDisabledColor以下列方式:

final myDropDownMenu = DropdownButton<String>(
      iconEnabledColor: Colors.white,
      iconDisabledColor: Colors.white,
      value: myInitialValue,
      // The rest of your code
);
Run Code Online (Sandbox Code Playgroud)


che*_*ins 5

由于DropdownButton取自最近的颜色,因此Theme有两个选择。

第一个是通过更改应用程序主题的亮度。

另一种是将dropdown按钮换成Theme深色的包装brightness

Theme(
   data: Theme.of(context).copyWith(brightness: Brightness.dark),
   child: DropdownButton(
     style: TextStyle(color: Colors.white, decorationColor: Colors.white),
     items: this.items,
     value: null,
     hint: Text(SaveOptions[_saveOption], style: TextStyle(color: Colors.white)),
     onChanged: (selectedOption) {
       setState(() {
         _saveOption = selectedOption;
       });
     },
   ),
 )
Run Code Online (Sandbox Code Playgroud)