I want to add on tap function to my bottom nav bar items, My code looks like this:
BottomNavigationBarItem(
icon: Icon(
Icons.settings,
color: Colors.grey,
)
)
I want to add on tap function to my bottom nav bar items, My code looks like this:
BottomNavigationBarItem(
icon: Icon(
Icons.settings,
color: Colors.grey,
)
)
There is an onTap function of BottomNavigationBar , example code
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.call),
label: 'Calls',
),
BottomNavigationBarItem(
icon: Icon(Icons.camera),
label: 'Camera',
),
BottomNavigationBarItem(
icon: Icon(Icons.chat),
label: 'Chats',
),
],
onTap: (i) {
},
As mentioned in Previous answer the onTap
function is used to interact with the bottomNavbar
items. The i
in it is for index.
onTap: (i) {
if(i == 0){
print("tapped on calls");
}
if(i == 1){
print("tapped on camera");
}
if(i == 2){
print("tapped on chats");
}
},
Now in the conditions just add what you want to do when clicked on bNavBar
items.