繁体   English   中英

如何将 TextStyle 和 textTheme 应用到 Flutter 中的 Text 小部件?

[英]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)

并将其应用于样式

由于空安全特性,合并方法会导致 Flutter 2.2 中的错误。 不要忘记添加“?” 变量之后。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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