【问题标题】:How to change dropdown default text color, when it is disabled?禁用时如何更改下拉默认文本颜色?
【发布时间】:2022-10-21 02:04:00
【问题描述】:

当下拉菜单被禁用时,它有这个默认的黑色文本颜色,我想改变它。有一个更改图标颜色的选项,但没有更改文本颜色的选项。
任何帮助将不胜感激。

DropdownButtonFormField(
        value: widget.selectedValue,
        items: widget.dropdownItems,
        dropdownColor: customTheme.colors.black30,
        iconEnabledColor: customTheme.colors.textColor,
        iconDisabledColor: Color.fromARGB(143, 144, 144, 144),

【问题讨论】:

    标签: flutter dart flutter-dropdownbutton


    【解决方案1】:

    更改主题的属性disabledColor 或使用Theme 小部件:

    Theme(
            data: Theme.of(context).copyWith(disabledColor: AppColors.primaryColor),
            child: DropdownButtonFormField(
                value: widget.selectedValue,
                items: widget.dropdownItems,
                dropdownColor: customTheme.colors.black30,
                iconEnabledColor: customTheme.colors.textColor,
                iconDisabledColor: Color.fromARGB(143, 144, 144, 144),
            ),
    ),
    

    【讨论】:

      【解决方案2】:

      您可以使用样式更改

      style: const TextStyle(
             color: Colors.pink,
             backgroundColor: Colors.grey,
      ),
      

      在这里你可以找到更多: https://www.flutter-code.com/2021/06/flutter-dropdownbutton-selected-text.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-23
        • 1970-01-01
        • 2016-10-23
        • 1970-01-01
        • 2021-08-24
        • 1970-01-01
        • 1970-01-01
        • 2020-02-05
        相关资源
        最近更新 更多