如何将 TextStyle 和 textTheme 应用于 Flutter 中的文本小部件?

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

对于像这样的文本:

Text(
   'Hello World',
   style: Theme.of(context).textTheme.display1,
    )

有没有办法将 textTheme 与 TextStyle 合并?比如修改文字颜色..

我们做类似的事情

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

并将其应用于样式

Merge 方法在 Flutter 2.2 中由于空安全特性而导致错误。 不要忘记添加“?”在变量之后。

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