Flutter - BottomNavigationBarItem 颜色设置

4,967 阅读1分钟
//设置颜色详见注释
bottomNavigationBar: BottomNavigationBar(
  items: bottomTabs.map((text) => BottomNavigationBarItem(       
     icon: Icon(bottomTabIcon[text]),         
     label: text,    
    )).toList(),
  currentIndex: _selectIndex,
  unselectedItemColor: Colors.grey,//主要用于设置item及字体颜色
  selectedItemColor: Colors.red,//主要用于设置item及字体颜色
  unselectedIconTheme: IconThemeData(color: Colors.orange),//主要用于设置icon颜色,作用优先于unselectedItemColor
  selectedIconTheme: IconThemeData(color: Colors.cyanAccent),//主要用于设置icon颜色,作用优先于selectedItemColor
  // fixedColor: Colors.red, // 与selectedItemColor冲突,不能共存
  unselectedLabelStyle: TextStyle(color: Colors.green),//有设置主题与unselectedItemColor时,无作用 
  selectedLabelStyle: TextStyle(color: Colors.yellow),////有设置主题与selectedItemColor时,无作用 
  iconSize: 30,
  type: BottomNavigationBarType.fixed,//item > 3时必须要设置,不然未选中项字体颜色变白
  onTap: (index) {
    setState(() {
      _selectIndex = index;
    });
  },
),