Bhaskar
Bhaskar

Reputation: 1946

How to apply both TextStyle and textTheme to a Text widget in flutter?

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..

Upvotes: 2

Views: 1705

Answers (2)

galiperkin
galiperkin

Reputation: 23

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)

Upvotes: 1

Bhaskar
Bhaskar

Reputation: 1946

We do something like

Theme.of(context)
.textTheme.display1
.merge(TextStyle(color: Colors.red)

and apply it to the style

Upvotes: 6

Related Questions