繁体   English   中英

你能改变 flutter 文本主题吗?

[英]Can you change flutter text theme?

如果主题在 main.dart 中设置为

return MaterialApp(
  title: 'MY APP',
  theme: ThemeData(
    primarySwatch: Colors.blue,
    fontFamily: 'Cabin',
    textTheme: TextTheme(
      headline1: TextStyle(
        fontFamily: 'Raleway',
        color: Colors.black,
        fontWeight: FontWeight.w600,
        fontSize: 18,
      ),
      subtitle1: TextStyle(
        fontFamily: 'Raleway',
        color: Colors.black54,
        fontWeight: FontWeight.w600,
        fontSize: 16,
      ),
    ),
  ),

我正在使用主题作为

Text('MY STRING',
    style: Theme.of(context).textTheme.subtitle1),

如何使“我的字符串”成为与 subtitle1 主题颜色不同的颜色,同时保留主题数据的其他属性,例如字体粗细、系列和大小等?

您可以使用 de 方法copyWith(color: your_color)来更改 TextTheme 的属性。

例子:

Text('MY STRING',
  style: Theme.of(context).textTheme.subtitle1
    .copyWith(color: Colors.red),
)

文档参考: https://api.flutter.dev/flutter/material/TextTheme/copyWith.html

暂无
暂无

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

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