flutter - 如何更改 ElevatedButton 和 OutlinedButton 的禁用颜色
问题描述
ElevatedButton
和小部件中没有这样的属性OutlinedButton
可以像常规一样更改禁用的颜色RaisedButton
。
ElevatedButton(
onPressed: null,
disabledColor: Colors.brown, // Error
}
解决方案
onSurface
如果您只想更改禁用的颜色,请使用属性(此属性在 中也可用OutlinedButton
)。
ElevatedButton(
onPressed: null,
style: ElevatedButton.styleFrom(
onSurface: Colors.brown,
),
child: Text('ElevatedButton'),
)
如需更多自定义,请使用ButtonStyle
:
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
您的应用程序中的所有内容:
MaterialApp(
theme: ThemeData(
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
onSurface: Colors.brown
),
),
),
)
推荐阅读
- python - Python:没有外部库的烧瓶简单任务队列不起作用
- python-3.x - 熊猫找到最大列,从另一列中减去并替换值
- svg - 从 SVG 文件夹创建一个 Eleventy 集合
- xml - SSRS 报告 - 从 API 获取数据
- git - 使用快捷方式在特定行撤消 vscode 中的本地更改
- javascript - 重新连接私有 Typescript 类方法
- visual-studio-code - 我删除了显示错误的底部栏 VScode,我该如何恢复它?
- java - Spring Gateway - 添加默认请求和响应标头
- flurry - Flurry 视图设置以在表格视图中显示数据
- r - R Shiny:根据输入小部件重新排列列