unselectedLabelstyle 在 Flutter 中不起作用

5 navbar dart flutter

为什么我的unselectedLabelStyle对我不起作用?\n在这个 unselectedLabelStyle 中使用 textStyle 属性保存我的更改后,对我来说什么都不会改变:/

\n\n
class _NavBarState extends State<NavBar> {\n  int _selectedPage = 0;\n\n  PageController pageController = PageController();\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: PageView(\n        controller: pageController,\n        children: <Widget>[\n          HomeScreen(),\n          MapScreen(),\n          SearchScreen(),\n          AccountScreen(),\n        ],\n      ),\n      bottomNavigationBar: BottomNavigationBar(\n        type: BottomNavigationBarType.fixed,\n        currentIndex: _selectedPage,\n        backgroundColor: Colors.white,\n        selectedIconTheme: IconThemeData(color: Colors.black, size: 32),\n        // selectedLabelStyle: TextStyle(fontWeight: FontWeight.bold),\n        unselectedIconTheme: IconThemeData(size: 26, color: Colors.grey.shade300),\n        unselectedLabelStyle: TextStyle(color: Colors.grey.shade300),//HEEEEEERRRRRRRRREEEEEE\n        onTap: (int index) {\n          setState(() {\n            _selectedPage = index;\n          });\n\n          pageController.animateToPage(\n            index,\n            duration: Duration(milliseconds: 500),\n            curve:\n                Curves.easeInOutExpo, \n          );\n        },\n        items: [\n          BottomNavigationBarItem(\n              icon: Icon(\n                Icons.home,\n              ),\n              title: Text('G\xc5\x82\xc3\xb3wna', style: TextStyle(color: Colors.black))),\n          BottomNavigationBarItem(\n              icon: Icon(\n                Icons.location_on,\n              ),\n              title: Text('Mapa', style: TextStyle(color: Colors.black))),\n          BottomNavigationBarItem(\n              icon: Icon(\n                Icons.search,\n              ),\n              title: Text('Szukaj', style: TextStyle(color: Colors.black))),\n          BottomNavigationBarItem(\n            icon: Icon(\n              Icons.person,\n            ),\n            title: Text('Konto', style: TextStyle(color: Colors.black)),\n          ),\n        ],\n      ),\n    );\n  }\n\n  @override\n  void dispose() {\n    pageController.dispose();\n    super.dispose();\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Vir*_*iya 5

您可以通过直接在标题中提供标题样式来重叠 textStyle,此外,您可以使用unselectedItemColor属性来更改未选择项目的颜色。

\n\n
unselectedItemColor: Colors.grey,\n
Run Code Online (Sandbox Code Playgroud)\n\n

更改标题自

\n\n
 title: Text('G\xc5\x82\xc3\xb3wna', style: TextStyle(color: Colors.black))),\n
Run Code Online (Sandbox Code Playgroud)\n\n

到:

\n\n
 title: Text('G\xc5\x82\xc3\xb3wna')),\n
Run Code Online (Sandbox Code Playgroud)\n\n

此外,我认为你应该在 flutter sdk 中提交错误,因为它没有像你提到的那样按预期工作。

\n\n
 /// If [selectedLabelStyle.color] and [unselectedLabelStyle.color] values\n  /// are non-null, they will be used instead of [selectedItemColor] and\n  /// [unselectedItemColor].\n
Run Code Online (Sandbox Code Playgroud)\n\n

根据以下文档注释,如果您指定 unselectedLabelStyle 的颜色,那么它应该使用该颜色,但它没有使用它。

\n