Home > OS >  Boolean controlled textstyle in Flutter?
Boolean controlled textstyle in Flutter?

Time:09-27

I have a boolean that controls the design of a container, its color, decoration, etc. based on if it is True or not. Is there a possible way for it to control the style of any text that is put into it?

CodePudding user response:

You can use two kind of style in extra file and switch:

style: isBoolean ? firstTextstyle : secondTextstyle,

In another file create two textstyle and use above:

final firstTextstyle = Textstyle();

You can use theme here like this question and answer

CodePudding user response:

You can use it by creating a TextStyle object according to the situation.

bool b =true;
TextStyle t1 = TextStyle(fontSize: 10);//true TextStyle
TextStyle t2 = TextStyle(fontSize: 20);//false TextStyle
    
Text('text', style: b ? t1 : t2,);
  • Related