【问题标题】:Flutter Change Dropdown arrow colorFlutter 更改下拉箭头颜色
【发布时间】:2019-06-18 11:34:50
【问题描述】:

如何改变下拉箭头的颜色?

这就是我想要的

这就是我得到的

我的小部件:

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

我尝试使用主题包装并更改亮度,但它仅将箭头从白色更改为黑色。我想用其他颜色。

【问题讨论】:

    标签: flutter dart colors dropdown


    【解决方案1】:

    这可以通过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(),
                ),
              ),
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-16
        • 2020-01-12
        • 1970-01-01
        • 1970-01-01
        • 2022-08-19
        • 2017-02-11
        • 2015-02-10
        • 2018-01-11
        相关资源
        最近更新 更多