【问题标题】:Can you change flutter text theme?你能改变颤动的文字主题吗?
【发布时间】:2021-06-10 19:14:08
【问题描述】:

如果主题在 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),

如何使“MY STRING”成为不同于 subtitle1 主题颜色的颜色,同时保留主题数据的其他属性,例如字体粗细和字体大小等?

【问题讨论】:

    标签: flutter material-design flutter-web flutter-theme


    【解决方案1】:

    您可以使用 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

    【讨论】:

    • 正是我想要的,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    相关资源
    最近更新 更多