Flutter 如何在声明后添加到主题数据变量?
我有一个独特的情况,如果我可以在声明后向一个主题数据变量添加一个属性,这将节省我很多时间 当前我的主题数据在themes.dart文件中声明:Flutter 如何在声明后添加到主题数据变量?,flutter,dart,Flutter,Dart,我有一个独特的情况,如果我可以在声明后向一个主题数据变量添加一个属性,这将节省我很多时间 当前我的主题数据在themes.dart文件中声明: ThemeData lightTheme() { return ThemeData( scaffoldBackgroundColor: Colors.white, fontFamily: "Open Sans", appBarTheme: appBarTheme(), textTheme: text
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稍后在典型主题:lightTheme()的main.dart中用作MaterialApp属性
然后,我想更改body.dart文件中使用headline1 TextTheme的headline1 TextTheme的字体大小:
Text(
'Hello,',
textAlign: TextAlign.left,
style: Theme.of(context).textTheme.headline1, //I want to add a line for fontSize here
),
我该怎么做?非常感谢您的帮助:)使用.copyWith()
作为:
style:Theme.of(context.textTheme.headline1.copyWith(fontSize:17)
正是我想要的,非常感谢:)很高兴帮助你。:)