Flutter更改下拉箭头颜色

8

如何更改下拉菜单箭头的颜色?

这是我想要的效果:

enter image description here

这就是我得到的

enter image description here

我的小部件:

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

我尝试使用主题和更改亮度进行包装,但它只会将箭头从白色变为黑色。我想使用其他颜色。

2个回答

29

这可以通过在DropdownButton中使用icon:属性来实现。

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

5

感谢@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(),
          ),
        ),

enter image description here


谢谢Favas,是的,这确实是一个改变游戏规则的东西 :) - Ehab Reda

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接