【发布时间】:2020-03-08 02:01:18
【问题描述】:
我想在深色和浅色主题模式下更改 bottomNavigationBar 的 unselectedItemColor 和 selectedItemColor 颜色。
我想要一个bottomNavigationBar的通用主题,但是在ThemeData中没有bottomNavigationBar主题的属性。
现在我正在像这样在运行时检查明暗模式,
var brightness = MediaQuery.of(context).platformBrightness;
BottomNavigationBar(
unselectedItemColor: brightness == Brightness.light
? AppColors.colorHint
: Colors.white70,
selectedItemColor: brightness == Brightness.light
? AppColors.themeColor
: AppColors.themeColor.shade200,
);
但我想在我的 main.dart 中有专门的 BottomNavigationBar 主题, 就像我在这里声明 appBarTheme 一样,我也想为 Dark 和 Light 模式声明 BottomNavigationBar 主题。
ThemeData _buildDarkTheme() {
final ThemeData base = ThemeData(
brightness: Brightness.dark,
appBarTheme: AppBarTheme(
textTheme: TextTheme(title: AppStyle.titleDark)
),
);
return base;
}
final ThemeData kLightTheme = _buildLightTheme();
final ThemeData kDarkTheme = _buildDarkTheme();
runApp(
MaterialApp(
theme: kLightTheme,
darkTheme: kDarkTheme,
)
);
【问题讨论】:
标签: flutter dart material-design flutter-layout