gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 04:39:22 25 4
gpt4 key购买 nike

我有一种独特的情况,如果我可以在声明后将属性添加到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),
)
}
后来在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
),
我怎样才能做到这一点?非常感谢您的帮助:)

最佳答案

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

关于flutter - 声明后如何添加到ThemeData变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63526004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com