Flutter 底部导航栏标题颜色

时间:2021-03-31 19:23:06

标签: flutter dart flutter-layout

我需要帮助来改变标题的颜色,当它被选中时。现在它是蓝色的,但我想把它改成黑色。这是我的代码

Widget build(BuildContext context) {
return Scaffold(
  body: Center(
    child: _widgetOptions.elementAt(_selectedIndex),
  ),
  bottomNavigationBar: BottomNavigationBar(
    items: <BottomNavigationBarItem> [
      BottomNavigationBarItem(  
        activeIcon: Icon(
          Icons.store,
          color: Colors.black,
        ),
        icon: Icon(
          Icons.store,        
          color: Colors.grey,    
        ),
        title: Text(
          'Ponuky',
          style: GoogleFonts.josefinSans(
            fontWeight: FontWeight.w600,
          ),
        ),
      ),

2 个答案:

答案 0 :(得分:0)

title 中的

BottomNavigationBarItem 现在已弃用,您必须使用 label 而不是 title 并使用属性对其进行样式设置。

How to style BottomNavigationBarItem label

答案 1 :(得分:0)

在项目结束括号后添加这两行

selectedItemColor: Colors.black, unselectedItemColor: Colors.blue,

  bottomNavigationBar: BottomNavigationBar(
    items: <BottomNavigationBarItem> [
      BottomNavigationBarItem(  
        activeIcon: Icon(
          Icons.store,
          color: Colors.black,
        ),
        icon: Icon(
          Icons.store,        
          color: Colors.grey,    
        ),
        title: Text(
          'Ponuky',
          style: GoogleFonts.josefinSans(
            fontWeight: FontWeight.w600,
          ),
        ),
      ),],
      selectedItemColor: Colors.black,
      unselectedItemColor: Colors.blue,