【问题标题】:I want to change the color of TextButton using Functions我想使用函数更改 TextButton 的颜色
【发布时间】:2021-08-31 11:43:40
【问题描述】:

enter image description here

-> backgroundColor: MaterialStateProperty.all(Colors.color),

//这里出现错误

【问题讨论】:

  • backgroundColor: MaterialStateProperty.all(Colors.red), 应该将您的按钮显示为红色。

标签: function flutter dart button colors


【解决方案1】:

没有颜色你会影响颜色

backgroundColor: MaterialStateProperty.all(color)

【讨论】:

    【解决方案2】:

    这样就可以了

    backgroundColor: MaterialStateProperty.all(Colors.red), // Or whatever color
    

    但如果您需要更多控制权。这样做

    MaterialStateProperty.resolveWith<Color>(
              (states) {
                if (states.contains(MaterialState.disabled)) {
                  return greyColor;
                }else if (states.contains(MaterialState.error)) {
                  return Colors.red;
                }
                 // Check other stated too. As per your need
                return selectedPrimaryColor;
              },
            ),
    

    【讨论】:

      猜你喜欢
      • 2022-10-07
      • 2015-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      • 2021-06-27
      • 2021-07-02
      • 1970-01-01
      相关资源
      最近更新 更多