How to include if statement in dart's TextStyle

1,216

Use conditional statement like below.

Text(
       "Hello",
        style: TextStyle(
        fontWeight: textBold ? FontWeight.bold : FontWeight.normal
       ),
      ),
Share:
1,216
DaleRoyFall
Author by

DaleRoyFall

Updated on December 01, 2022

Comments

  • DaleRoyFall
    DaleRoyFall over 1 year

    I have a TextStyle and a variable textBold that can be true or false. How to implement if in this TextStyle?

    TextStyle(
        color: Colors.white,
        if ($textBold == true){
          fontWeight: FontWeight.bold,
        }
    
  • DaleRoyFall
    DaleRoyFall over 4 years
    Thanks, I completely forgot about this if's form
  • DaleRoyFall
    DaleRoyFall over 4 years
    I understand that i could do something like that in children, but in style i couldn't
  • Farmaan Elahi
    Farmaan Elahi over 4 years
    That isn't supported as of now in Dart