Search code examples
flutterdartflutter-layoutbottomnavigationview

Change BackGround Color of BottomNavigationBar?


I'm using Flutter's Nested Navigators plugin https://pub.dev/packages/nested_navigators.

I believe I should be able to change the background color of the BottomNavigationBar using backgroundColor as a parameter;

buildBottomNavigationItem: (key, item, selected) =>
          BottomNavigationBarItem(
            icon: Icon(
              item.icon,
              color: Colors.blue,
            ),
            title: Text(
              item.text,
              style: TextStyle(fontSize: 14),
            ),
          ),
     bottomNavigationBarTheme: Theme.of(context).copyWith(
       splashColor: Colors.blue[200],
       primaryColor: Colors.green[300],
       backgroundColor: Colors.orange,
      ),

But alas, the BottomNavigationBar stubbornly refuses to be anything other than white. Any idea what's going wrong?


Solution

  • The solution was to replace buildBottomNavigationItem with

    buildCustomBottomNavigationItem: (key, item, selected) => Container(
             color: Color(0xffb79eb5).withOpacity(.70),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  Icon(
                    item.icon,
                    size: 18,
                    color: selected ? Colors.white : Colors.black38,
                  ),
                  Text(
                    item.text,
                    style: TextStyle(fontSize: 16, color: selected ? Colors.white : Colors.black38),
                  ),
                ],
              ),
            ),