1

I am trying to find how can I know from which screen user has clicked the bottom nav screen. Basically I have to send event from which screen user clicked on botton nav. I have 4 bottom nav.

vikas pandey
  • 199
  • 2
  • 15

2 Answers2

2

There is no direct way to check a previously selected item in the bottom bar what you can do you can make use of

onTap: (index) => changeTab(index)

It gives an index of the item user taps, Save index to some variable, and next time when use tap on the item you can consider previously saved value as an item from which the user is tapping.

Shripad Jadhav
  • 316
  • 1
  • 8
0

You can check the last selected index in bottom navigation bar :

 static int currentTab = 0;
 static int lastIndex = 0;

When you implement the onPressed or onTap method on bottom bar:

 onTap: (){
  setState(() {
      currentTab = index;
      lastIndex = currentTab;    // It keeps the last selected index.
    }
  });
}

And then u can call

    currentTab = lastIndex.
Nisha Jain
  • 637
  • 6
  • 14