简体   繁体   中英

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

We do something like

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

and apply it to the style

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM