Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include if statement in dart's TextStyle

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,
    }

1 Answers

Use conditional statement like below.

Text(
       "Hello",
        style: TextStyle(
        fontWeight: textBold ? FontWeight.bold : FontWeight.normal
       ),
      ),
like image 69
Hussnain Haidar Avatar answered Oct 20 '25 15:10

Hussnain Haidar