flutter-caffold提供黑色背景,而不是我的自定义颜色
我将apptheme
类做如下:
class AppTheme {
static const Color white = Colors.white,
white2 = Color(0x00fefefe),
grey1 = Color(0x00e5e5e5),
grey2 = Color(0x006b718b),
grey3 = Color(0x004b4a5a),
grey4 = Color(0x00AFBEC4),
black = Colors.black,
purple = Color(0x007154b8);
static const TextStyle s1 = TextStyle(
color: AppTheme.black,
fontSize: 16,
fontWeight: FontWeight.w600,
height: 2.4,
),
s2 = TextStyle(
color: AppTheme.black,
fontSize: 14,
fontWeight: FontWeight.w600,
height: 2.1,
),
s3 = TextStyle(
color: AppTheme.grey3,
fontSize: 12,
height: 1.8,
fontWeight: FontWeight.w500,
),
s4 = TextStyle(
fontSize: 10,
color: AppTheme.purple,
height: 1.5,
fontWeight: FontWeight.w500,
);
static final ThemeData theme = ThemeData(
fontFamily: 'Poppins',
textTheme: const TextTheme(
headlineMedium: s2,
bodyLarge: s1,
bodyMedium: s3,
bodySmall: s4,
),
scaffoldBackgroundColor: grey1,
bottomAppBarColor: white,
);
}
然后,我为主题的apptheme.theme.theme.theme
提供了yeartialapp
。但是,每当我使用自定义颜色时,例如
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
我的自定义颜色,我都会得到一个完全黑色的脚手架。即使直接用作apptheme.grey1
,我也会得到一个完全黑色的脚手架。我在做什么错以及如何解决?
I made an AppTheme
class as follows :
class AppTheme {
static const Color white = Colors.white,
white2 = Color(0x00fefefe),
grey1 = Color(0x00e5e5e5),
grey2 = Color(0x006b718b),
grey3 = Color(0x004b4a5a),
grey4 = Color(0x00AFBEC4),
black = Colors.black,
purple = Color(0x007154b8);
static const TextStyle s1 = TextStyle(
color: AppTheme.black,
fontSize: 16,
fontWeight: FontWeight.w600,
height: 2.4,
),
s2 = TextStyle(
color: AppTheme.black,
fontSize: 14,
fontWeight: FontWeight.w600,
height: 2.1,
),
s3 = TextStyle(
color: AppTheme.grey3,
fontSize: 12,
height: 1.8,
fontWeight: FontWeight.w500,
),
s4 = TextStyle(
fontSize: 10,
color: AppTheme.purple,
height: 1.5,
fontWeight: FontWeight.w500,
);
static final ThemeData theme = ThemeData(
fontFamily: 'Poppins',
textTheme: const TextTheme(
headlineMedium: s2,
bodyLarge: s1,
bodyMedium: s3,
bodySmall: s4,
),
scaffoldBackgroundColor: grey1,
bottomAppBarColor: white,
);
}
I then provided the AppTheme.theme
to the MaterialApp
for theme. However whenever I am using my custom colors, for example
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
instead of my custom color, I am getting a completely black scaffold. Even when using directly as AppTheme.grey1
I am getting a completely black scaffold. What am I doing wrong and how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改 themedata 这样的代码:
和内部 main 这样的主题对象这样:
以下是结果:

Change your code for ThemeData like this:
And inside Main define the theme object like this:
Here is the result:
