-1

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,
  )
)
Hamed
  • 5,867
  • 4
  • 32
  • 56

2 Answers2

1

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) {
         

        },
1

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.

Top4o
  • 547
  • 6
  • 19
Vivek Chib
  • 837
  • 1
  • 2
  • 13