The Label Color doesn't change on the BottomNavigationBar

1k views Asked by At

The color of the labels of my selected and unselected BottomNavigationBarItems doesn't change... what am I doing wrong? Here is the code:

bottomNavigationBar: BottomNavigationBar(
        selectedLabelStyle: TextStyle(color: Colors.black),
        unselectedLabelStyle: TextStyle(color: Colors.black),
        backgroundColor: Colors.white,
        
        onTap: onTabTapped,
        currentIndex: _currentIndex, // this will be set when a new tab is tapped
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home, color: Colors.black,),
            label: 'Home',

          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.search, color: Colors.black,),
            label: 'Messages',
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.person, color: Colors.black,),
              label: 'Profile'
          )
        ],
      ),
5

There are 5 answers

0
Pranshul Agrawal On

You can use the child property and add the text class in which you can style your text easily

0
Raiyan On

Change this

selectedLabelStyle: TextStyle(color: Colors.black),
unselectedLabelStyle: TextStyle(color: Colors.black),

To this:

selectedItemColor: Colors.black,
unselectedItemColor: Colors.black,
0
Ikhiloya Imokhai On

Add this to your Bottom Navigation Bar style:

showUnselectedLabels: true,

0
Md. Yeasin Sheikh On

The common mistake can be putting _currentIndex inside build method. Follow

 int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        selectedLabelStyle: TextStyle(color: Colors.black),
        unselectedLabelStyle: TextStyle(color: Colors.black),
        backgroundColor: Colors.white,
        onTap: (v) {
          _currentIndex = v;
          print(v);
          setState(() {});
        },
        currentIndex: _currentIndex,
        items: [
0
Kiran Jadhav On

Use below simple solution to change the selectedLabelStyle and unselectedLabelStyle - (color for label text ):

          BottomNavigationBarItem(
            activeIcon: Image.asset(
              "assets/images/race_icon_fill.png",
              height: 30,
              width: 30,
              fit: BoxFit.cover,
              color: appThemeColor,
            ),
            icon: Image.asset(
              "assets/images/race_icon.png",
              height: 30,
              width: 30,
              fit: BoxFit.cover,
              color: appLightGrayColor,
            ),
            label: 'My Races',
          ),

==========================================

            selectedItemColor: Colors.black,
            unselectedItemColor: Colors.grey,
            selectedLabelStyle: const TextStyle(
                fontWeight: FontWeight.w500, fontFamily: AlbertSans),
            unselectedLabelStyle: const TextStyle(
                fontWeight: FontWeight.w300, fontFamily: AlbertSans, color: Colors.deepPurple),