Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change color of IconButton after pressed in flutter

Tags:

flutter

dart

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?

    });
  },
),
like image 951
Heyran.rs Avatar asked Mar 10 '19 19:03

Heyran.rs


People also ask

How do I change my IconButton color on click flutter?

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 do you click icons on flutter?

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.


1 Answers

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;
        });
      },
    );
  }
}
like image 198
Ajil O. Avatar answered Oct 01 '22 01:10

Ajil O.