Flutter:ThemeData中bottomNavigationBar的常见深色和浅色主题

问题描述 投票:1回答:1

我想在深色和浅色主题模式下都更改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一样,我也要为暗和亮模式都声明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
1个回答
1
投票

您可以在]使用此代码>

bottomNavigationBar: new Theme(
  data: Theme.of(context).copyWith(),  
  child: new BottomNavigationBar(items: [  new BottomNavigationBarItem(),] ),

)


© www.soinside.com 2019 - 2024. All rights reserved.