I want to change color of icon after pressing. how can I do it?
My IconButton
is leading of a ListTile
.
leading: new IconButton(
icon: Icon(Icons.star, color: Colors.white),
onPressed: () {
setState(() {
//color: Colors.yellow; //How?
});
},
),
Steps to change icon button color in FlutterLocate the file where you have placed the IconButton widget. Inside the IconButton widget, add the color parameter and assign the color of your choice. Run the App.
How to Make Icon Clickable in Flutter? You can wrap Icon() widget with InkWell or alternatively GestureDetector() widget to make icons clickable in your Flutter app.
You could do something like this
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;
});
},
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With