![](/img/trans.png)
[英]TextButton.icon and ElevatedButton.icon: is it possible to show the label first then the icon?
[英]How to change color in TextButton.icon
我想要一个带有文本的图标,所以我使用TextButton.icon
但我无法更改文本或图标的颜色:请建议是否有人有解决方案这是我的代码:
SizedBox(height: 8,),
TextButton.icon(
icon: Icon(Icons.delete),
label: Text('delete'),
onPressed: (){},
),
您可以在 TextButton 的样式上使用 TextButton.stylefrom。 在这种方法中,您可以使用 primary 来设置图标和标签的颜色。 如果要为图标设置另一种颜色,可以在 Icon 中设置图标颜色。
TextButton.icon(
onPressed:(){}),
style: TextButton.styleFrom(
primary: Colors.blue,
),
icon: Icon(Icons.ac_unit, color: Colors.red),
label: Text("label"),
)
基于Emmanuel Ashitey的回答,从 v3.1.0 开始,“主要”方法已被弃用(根据 VSCode 工具提示),应替换为“foregroundColor”:
TextButton.icon(
onPressed: () {},
icon: const Icon(Icons.delete),
label: const Text('Delete'),
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).errorColor,
),
),
对于这种情况,显然Theme.of(context).errorColor
可以替换为Colors.red
。
试试下面的代码希望它对你有帮助。
请参阅 此处TextButton
TextButton.icon(
icon: Icon(
Icons.delete,
color: Colors.red,//for icon color
),
label: Text(
'Delete',
style: TextStyle(
color: Colors.red,//for text color
),
),
onPressed: () {},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.