'Different icons with if else statement

I am using the following code in my Flutter application:

Row(
    children: [ _loading ? CircularProgressIndicator():
      //if(Text(data_snap['icon_spec'].toString()) == "abc"){
                   new Container(
                          width: SizeConfig.safeBlockHorizontal * 24,
                          alignment: Alignment.centerLeft,
                          child: Text(
                            'Test: ',
                            style: new TextStyle(
                                fontSize: SizeConfig.blockSizeHorizontal * 4, color: Colors.grey[750],
                                fontWeight: FontWeight.bold),
                          )),
                        new Container(
                          width: SizeConfig.safeBlockHorizontal * 10,
                          alignment: Alignment.centerLeft,
                          child: new IconTheme(
                            data: new IconThemeData(
                                color: Colors.yellow),
                            child: new Icon(Icons.trending_neutral_rounded),
                          ),
                        ),
                        new Container(
                            width: SizeConfig.safeBlockHorizontal * 16,
                            alignment: Alignment.centerLeft,
                            child: Text(
                              'Text: ',
                              style: new TextStyle(
                                  fontSize: SizeConfig.blockSizeHorizontal * 4, color: Colors.grey[750],
                                  fontWeight: FontWeight.bold),
                            )),
                        new Container(
                          width: SizeConfig.safeBlockHorizontal * 21,
                          child: Text(data_snap['abc'].toStringAsFixed(2)),
                        ),

                      ],
                    ),

Depending on the "icon_spec" from Firebasedata I would like to change the Icon and its color. For example: if "icon_spec = abc", the Icon should be a yellow trending_neutral_rounded. When "icon_spec = def", the Icon should be a red trending_down_rounded.

I tried it with the commented line in the code above but it doesn't work inside this children. How can I change the Icon and its color depending on the value from Firebase?



Solution 1:[1]

Container(
          width: SizeConfig.safeBlockHorizontal * 10,
          alignment: Alignment.centerLeft,
          child:  IconTheme(
            data:data_snap['icon_spec'].toString() == "abc" ?  
           IconThemeData(
                color: Colors.yellow),
            child:  Icon(Icons.trending_neutral_rounded),
          ):data_snap['icon_spec'].toString() == "def" ?  IconThemeData(
                color: Colors.yellow),
            child:  Icon(Icons.trending_neutral_rounded),
          ):IconThemeData(),
        ),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yeasin Sheikh