简体   繁体   English

Flutter 更改下拉箭头颜色

[英]Flutter Change Dropdown arrow color

How to change Dropdown arrow color?如何更改下拉箭头颜色?

Here is what I want :这是我想要的

在此处输入图片说明

This is what I get这就是我得到的

在此处输入图片说明

My widget:我的小部件:

            DropdownButtonHideUnderline (
          child: DropdownButton<String>(
            isExpanded: true,
            value: dropdownValue,
            onChanged: (String newValue) {
              setState(() {
                dropdownValue = newValue;
              });
            },
            items: <String>['Bank Deposit', 'Mobile Payment', 'Cash Pickup']
                .map<DropdownMenuItem<String>>((String value) {
              return DropdownMenuItem<String>(
                value: value,
                child: Text(value),
              );
            })
                .toList(),
          ),
        ),

I tried wrapping with Theme and changing Brightness, but it changes arrow from White to Black only.我尝试用主题包装并更改亮度,但它仅将箭头从白色更改为黑色。 I want to use some other color.我想用其他颜色。

This can be done with icon: property in DropdownButton这可以通过icon:属性在DropdownButton

DropdownButtonHideUnderline(
            child: DropdownButton<String>(
              isExpanded: true,
              value: dropdownValue,
              onChanged: (String newValue) {
                setState(() {
                  dropdownValue = newValue;
                });
              },
              hint: Text('Select'),
              icon: Icon(                // Add this
                Icons.arrow_drop_down,  // Add this
                color: Colors.blue,   // Add this
              ),
              items: <String>['Bank Deposit', 'Mobile Payment', 'Cash Pickup']
                  .map<DropdownMenuItem<String>>((String value) {
                return DropdownMenuItem<String>(
                  value: value,
                  child: Text(value),
                );
              }).toList(),
            ),
          ),

Thanks to @anmol.majhail, anyway found something simpler using iconEnabledColor property.感谢@anmol.majhail,无论如何使用iconEnabledColor属性发现了一些更简单的东西。

               DropdownButtonHideUnderline (
          child: DropdownButton<String>(

            iconEnabledColor: Colors.indigo, // game changer

            isExpanded: true,
            value: dropdownValue,
            onChanged: (String newValue) {
              setState(() {
                dropdownValue = newValue;
              });
            },
            items: <String>['Bank Deposit', 'Mobile Payment', 'Cash Pickup']
                .map<DropdownMenuItem<String>>((String value) {
              return DropdownMenuItem<String>(
                value: value,
                child: Text(value),
              );
            })
                .toList(),
          ),
        ),

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM