Flutter 如何更改ElevatedButton和OutlineButton中禁用的颜色?
在Flutter 如何更改ElevatedButton和OutlineButton中禁用的颜色?,flutter,Flutter,在relatedbutton和OutlinedButton小部件中没有这样的属性可以像常规的RaisedButton那样更改禁用的颜色 ElevatedButton( onPressed:null, disabledColor:Colors.brown,//错误 } 如果只想更改禁用的颜色,请使用onSurface属性(此属性也可在OutlinedButton中找到) ElevatedButton( onPressed:null, 样式:ElevatedButton.styleFrom( 表面:
relatedbutton
和OutlinedButton
小部件中没有这样的属性可以像常规的RaisedButton
那样更改禁用的颜色
ElevatedButton(
onPressed:null,
disabledColor:Colors.brown,//错误
}
如果只想更改禁用的颜色,请使用onSurface
属性(此属性也可在OutlinedButton
中找到)
ElevatedButton(
onPressed:null,
样式:ElevatedButton.styleFrom(
表面:颜色。棕色,
),
子项:文本('ElevatedButton'),
)
有关更多自定义,请使用按钮样式
:
ElevatedButton(
onPressed: null,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.disabled)) {
return Colors.brown; // Disabled color
}
return Colors.blue; // Regular color
}),
),
child: Text('ElevatedButton'),
)
ElevatedButton(
onPressed:null,
样式:钮扣样式(
backgroundColor:MaterialStateProperty.resolveWith((状态){
if(states.contains(MaterialState.disabled)){
return Colors.brown;//禁用颜色
}
return Colors.blue;//常规颜色
}),
),
子项:文本('ElevatedButton'),
)