dart 如何更改flutter material3 navigationBar小部件的标签文本颜色?

dauxcl2d  于 2024-01-03  发布在  Flutter
关注(0)|答案(1)|浏览(233)

我是Flutter的新手,正在开发Material 3应用程序。我试图自定义底部导航栏中选定标签文本的颜色,但我遇到了一些挑战。
以下是我迄今为止尝试的方法:
我尝试将TextStyle直接应用于标签文本,但这对所选项目的颜色没有任何影响。我还查看了BottomNavigationBar的文档,但我还没有找到一个简单的属性来修改选定的标签文本颜色。我希望为选定的标签文本实现一个特定的颜色,使其从标签项中脱颖而出。我欢迎任何指导或建议在材料3中如何处理这个问题。

  1. bottomNavigationBar: NavigationBar(
  2. onDestinationSelected: (int index) {
  3. setState(() {
  4. currentPageIndex = index;
  5. });
  6. },
  7. indicatorColor: HexColor('CEE7EF'),
  8. backgroundColor: HexColor('ffffff'),
  9. labelBehavior: labelBehavior,
  10. selectedIndex: currentPageIndex,
  11. destinations: const <Widget>[
  12. NavigationDestination(
  13. selectedIcon: Icon(Icons.home),
  14. icon: Icon(Icons.home_outlined),
  15. label: 'Home',
  16. ),
  17. NavigationDestination(
  18. icon: Icon(Icons.important_devices),
  19. label: 'Devices',
  20. ),
  21. NavigationDestination(
  22. icon: Icon(Icons.settings),
  23. label: 'Settings',
  24. ),
  25. ],
  26. ),

字符串

jvidinwx

jvidinwx1#

  1. NavigationBarTheme(
  2. data: NavigationBarThemeData(
  3. labelTextStyle: MaterialStateProperty.all(
  4. const TextStyle(
  5. fontSize: 12,
  6. fontWeight: FontWeight.w600,
  7. color: Colors.black,
  8. ),
  9. )),
  10. child: NavigationBar(
  11. onDestinationSelected: (int index) {
  12. setState(() {
  13. currentPageIndex = index;
  14. });
  15. },
  16. indicatorColor: HexColor('CEE7EF'),
  17. backgroundColor: HexColor('ffffff'),
  18. labelBehavior: labelBehavior,
  19. selectedIndex: currentPageIndex,
  20. destinations: const <Widget>[
  21. NavigationDestination(
  22. selectedIcon: Icon(Icons.home),
  23. icon: Icon(Icons.home_outlined),
  24. label: 'Home',
  25. ),
  26. NavigationDestination(
  27. icon: Icon(Icons.important_devices),
  28. label: 'Devices',
  29. ),
  30. NavigationDestination(
  31. icon: Icon(Icons.settings),
  32. label: 'Settings',
  33. ),
  34. ],
  35. ),
  36. );

字符串

展开查看全部

相关问题