how to change icon color immediately after pressed in flutter?

前端 未结 2 1724
刺人心
刺人心 2021-01-18 00:49

I would like to change the color of an icon after pressing it, but it seems the following code doesn\'t work.

  void actionClickRow(String key) {
    Navigat         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-18 01:22

    You can simply put a condition for each color :

    color:(isPressed) ? Color(0xff007397)
                            : Color(0xff9A9A9A))
    

    and in the onPressed function :

     onPressed: ()
                          {
                            setState(()
                            {
                              isPressed= true;
                            });                    
                          }
    

提交回复
热议问题