Home > Software design >  Set male or female icon based on the user input Flutter
Set male or female icon based on the user input Flutter

Time:06-23

I want to show either a male or a female icon based on what the user is, they choose the gender using a radio button while signing in. Now, inside, on the Profile page, I'm showing all information on that user.

I don't know if what I'm doing is even right, so here's the code:

InfoDesignUIWidget(
              textInfo:userModelCurrentInfo!.gender!,
                iconData:
                if(userModelCurrentInfo!.gender! == 'Male'){ // line 68
                   Icons.male_rounded;
              }
              else {
                  Icons.female_rounded;
              }
              ), 

I'm getting these errors: Expected an identifier. :68

Expected to find ')'. :68

CodePudding user response:

You're using an if statement where an expression is expected.

Use a ternary expression instead:

iconData: userModelCurrentInfo!.gender == 'Male' 
          ? Icons.male_rounded
          : Icons.female_rounded
  • Related