How to apply both TextStyle and textTheme to a Text widget in flutter?
924
Solution 1
We do something like
Theme.of(context)
.textTheme.display1
.merge(TextStyle(color: Colors.red)
and apply it to the style
Solution 2
Merge method causes error in Flutter 2.2 because of the null safety feature. Don't forget to add "?" after the variable.
Theme.of(context).textTheme.display1?.merge(TextStyle(color: Colors.red)
Comments
-
Bhaskar over 1 year
For a Text like:
Text( 'Hello World', style: Theme.of(context).textTheme.display1, )
Is there a way to merge textTheme with a TextStyle? Like say, to modify the color of the text..