Flutter中的新导航栏标签颜色

ha5z0ras  于 2023-05-23  发布在  Flutter
关注(0)|答案(1)|浏览(116)

我有一个导航栏,我想改变它的颜色,但我似乎找不到在文档中任何关于改变标签颜色,任何想法如何做到这一点?当前代码:

bottomNavigationBar: NavigationBar(
    backgroundColor: Colors.lightBlue[100]!,
    destinations: const [
      NavigationDestination(
        icon: Icon(Icons.home, color: Colors.white,),
        label: 'Home',
      ),
      NavigationDestination(
        icon: Icon(Icons.money, color: Colors.white),
        label: 'Expenses',
      ),
    ],
  ),

就我所能看到的标签是一个字符串,但我如何改变这个字符串的颜色呢?我的第一个想法是使用Text(),但label只接受字符串。
非常感谢您的评分!

wpcxdonn

wpcxdonn1#

您必须执行以下操作:
1.创建“your_file_name”_theme.dart。(您可以更改您的偏好颜色)

final ThemeData myappTheme = ThemeData(
  navigationBarTheme: NavigationBarThemeData(
    labelTextStyle: MaterialStateProperty.resolveWith((state) {
      if (state.contains(MaterialState.selected)) {
        return const TextStyle(color: Colors.orange);
      }
      return const TextStyle(color: Colors.green);
    }),
  ),
);

1.在您的MaterialApp小部件中,添加以下内容。(在我的例子中,我称之为myappTheme)

MaterialApp(
    theme: myappTheme,

1.重新启动应用

相关问题