你能改变颤动文本主题吗?

Mar*_*paG 3 material-design flutter flutter-web flutter-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,
      ),
    ),
  ),
Run Code Online (Sandbox Code Playgroud)

我使用主题作为

Text('MY STRING',
    style: Theme.of(context).textTheme.subtitle1),
Run Code Online (Sandbox Code Playgroud)

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

Gui*_*lli 9

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

例子:

Text('MY STRING',
  style: Theme.of(context).textTheme.subtitle1
    .copyWith(color: Colors.red),
)
Run Code Online (Sandbox Code Playgroud)

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