简体   繁体   中英

Change Icon Color in Alert Dialog Using setState of Different File

The problem I am facing is to change the color of an icon from a different class. Therefore, in my application, I need to trigger File 1's setState from File 2.

I have tried callback function but it is not working. Maybe due to lack of experience and understanding.

File 1 (full file is shown to provide a better understanding of my problem):

File 2 (Full file is shown to provide a better understanding of my problem) :

Currently, the icon in the alert dialog will only change its color when the alert dialog is reopened (This just trigger setState File 1 from File 1).

My expected result is when the button in the alert dialog is pressed, icon color change instantly without the need of reopened the alert dialogue.

Hopefully, someone may suggest me what and how to implement to achieve the expectation...

The color property defaults to the current IconTheme color, if any. Generally, a material design color will be used, as follows:

Icon(
 CustomIcon.MyFlutterApp.light,
 color: Colors.blue.shade400, //any color you want
 size: 100,
),

Or you could do like this:

child: new IconTheme(
    data: new IconThemeData(
        color: Colors.yellow), 
    child: new Icon(CustomIcon.MyFlutterApp.light),
),

BTW, I haven't checked the code but it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM