![](/img/trans.png)
[英]Flutter TextStyle (not TextTheme) difference between apply() and copyWith()
[英]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.