声明后如何添加到ThemeData变量?

时间:2020-08-21 15:46:21

标签: flutter dart

我有一个独特的情况,如果我可以在声明后将属性添加到ThemeData变量中,则可以节省很多时间。

当前,我的ThemeData是在themes.dart文件中声明的:

ThemeData lightTheme() {
  return ThemeData(
    scaffoldBackgroundColor: Colors.white,
    fontFamily: "Open Sans",
    appBarTheme: appBarTheme(),
    textTheme: textTheme(),
    inputDecorationTheme: inputDecorationTheme(),
    visualDensity: VisualDensity.adaptivePlatformDensity,
  );
}

TextTheme textTheme() {
  return TextTheme(
      headline1: TextStyle(
          color: Color(0xFF000000),
          //fontSize: getProportionateScreenWidth(25) I would like to declare this in a different file
          fontWeight: FontWeight.normal),
  )
}

ThemeData随后在main.dart中以典型主题使用:lightTheme()作为MaterialApp属性

然后我想在我使用headline1 textTheme的body.dart文件中更改headline1 TextTheme的fontSize:

Text(
  'Hello,',
  textAlign: TextAlign.left,
  style: Theme.of(context).textTheme.headline1, //I want to add a line for fontSize here 
),

我该怎么做?非常感谢您的帮助:)

1 个答案:

答案 0 :(得分:1)

.copyWith()用作:

style: Theme.of(context).textTheme.headline1.copyWith(fontSize: 17)