我想在按下后改变图标的颜色。我该怎么做?
我的 IconButton
是 ListTile
的前导。
leading: new IconButton(
icon: Icon(Icons.star, color: Colors.white),
onPressed: () {
setState(() {
//color: Colors.yellow; //How?
});
},
),
最佳答案
你可以这样做
class SomeState extends State<StatefulWidget> {
Color _iconColor = Colors.white;
@override
Widget build(BuildContext) {
return ListTile(
leading: new IconButton(
icon: Icon(Icons.star, color: _iconColor),
onPressed: () {
setState(() {
_iconColor = Colors.yellow;
});
},
);
}
}
关于dart - 如何在 flutter 中按下后更改 IconButton 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55091272/