Material Button disabledColor 未在 Flutter 中显示输入的颜色

Akr*_*han 4 flutter

当 Material 按钮被禁用时,我试图显示不同的颜色。我正在添加属性 disabledColor 和 disabledTextColor。但是, disabledTextColor 显示输入的确切颜色,但 disabledColor 不显示任何颜色。

这是我的代码

disabledColor:Colors.grey, // 不适用于按钮的背景颜色 disabledTextColor:Colors.black, // 适用于按钮的文本颜色

MaterialButton(
  padding: EdgeInsets.all(10.0),
  disabledElevation: 1,
  disabledColor: Colors.black45,
  disabledTextColor: Colors.white70,
  color:Colors.indigo,
  textColor: Colors.white,
  child: Text("Verify",style: TextStyle(
    fontSize: 18.0,
  ),),
  onPressed: null,
),
Run Code Online (Sandbox Code Playgroud)

我希望输出应该显示灰色作为背景颜色和黑色作为文本颜色。

die*_*per 6

看起来MaterialButton小部件上存在错误,disabledColor未使用该变量,请尝试使用RawMaterialButton.

bool enabled = false;
...
   

RawMaterialButton(
  padding: EdgeInsets.all(10.0),
  disabledElevation: 1,
  fillColor: enabled ? Colors.indigo : Colors.black45,
  textStyle: TextStyle(color: enabled ? Colors.white : Colors.white70),
    child: Text(
      "Verify",
      style: TextStyle(
        fontSize: 18.0,
      ),
    ),
  onPressed: enabled ? () {} : null,
),

Run Code Online (Sandbox Code Playgroud)