I am trying out Flutter and I am trying to change the colour of the BottomNavigationBar
on the app but all I could achieve was change the colour of the Bo
The accepted answer isn't entirely wrong. However, BottomNavigationBar
does in-fact have a property of backgroundColor
. As per the documentation
If type is BottomNavigationBarType.shifting and the itemss, have BottomNavigationBarItem.backgroundColor set, the item's backgroundColor will splash and overwrite this color.
What this means is that the BottomNavigation
's backgroundColor will be overriden by the individual items backgroundColor because the default type is BottomNavigationBarType.shifting
.
To fix this, simply add the following property to the declared BottomNavigationbar
widget.
type: BottomNavigationBarType.fixed,
Note: If you do, however, want the shifting effect you will have to declare colors for each item, or wrap the widget that allows the overriding of the child widget(s) background color.
i.e Something like Container
widget.
You can currently style them BottomNavigationBar
directly from the Theme
, like this:
ThemeData(
bottomNavigationBarTheme: BottomNavigationBarThemeData(
backgroundColor: Colors.grey[900],
elevation: 10,
selectedLabelStyle: TextStyle(
color: Color(0xFFA67926), fontFamily: 'Montserrat', fontSize: 14.0),
unselectedLabelStyle: TextStyle(
color: Colors.grey[600], fontFamily: 'Montserrat', fontSize: 12.0),
selectedItemColor: Color(0xFFA67926),
unselectedItemColor: Colors.grey[600],
showUnselectedLabels: true,
),
)
Set following properties to change the background, selected and unselected colors
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.blue,
selectedItemColor: Colors.black,
unselectedItemColor: Colors.white,
type: BottomNavigationBarType.fixed,
...
)