Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set color of all text in a specific container in flutter?

Tags:

flutter

dart

I don't want to change the text color of the whole app. Just all the text inside a container. Can I wrap it with some other widget or something for this ?

like image 604
Steev James Avatar asked Aug 23 '19 10:08

Steev James


2 Answers

To apply certain TextStyle properties only to a subtree of your app. You can use DefaultTextStyle

DefaultTextStyle(
  child: Container(child: /* your subtree */),
  style: TextStyle(color: Colors.red),
),

as a comment pointed out, this replaces all defaults, not just the color. This can be mitigated by using the merge constructor:

DefaultTextStyle.merge(
  child: Container(child: /* your subtree */),
  style: TextStyle(color: Colors.red),
),
like image 158
ChrisG Avatar answered Sep 26 '22 13:09

ChrisG


Use DefaultTextStyle.merge to keep your theme and just change the color.

    DefaultTextStyle.merge(
        style: TextStyle(color: Colors.grey[400]),
        child: Column(...),
    )
like image 43
Travis Reeder Avatar answered Sep 26 '22 13:09

Travis Reeder