PersistentBottomNavBar
PersistentBottomNavBar copied to clipboard
Add popAllScreensForTheSelectedTab functionality for custom navbar
To enable custom navBars to pop all screens inside the tab when clicking the same nav/tab icon, the following are modified:
- Modify customWidget from widget to a widget builder
Widget Function(NavBarEssentials navBarEssentials) customWidgetexposing NavBarEssentials - Added
bool popAllScreensOnTapOfSelectedTab = trueandList<PersistentBottomNavBarItem> itemsinPersistentBottomNavBarItem.custom
Requirements:
popAllScreensOnTapOfSelectedTab == true and items = List<PersistentBottomNavBarItem> with length same with the screen
items: _buildScreens()
.map((e) => PersistentBottomNavBarItem.custom())
.toList(),
.....
customWidget: (NavBarEssentials navBarEssentials) => CustomNavBarWidget(
items: _navBarsItems(),
onItemSelected: (index) {
if (index == _controller.index)
navBarEssentials.popAllScreensForTheSelectedTab(index);
setState(() {
_controller.index = index; // THIS IS CRITICAL!! Don't miss it!
});
},
selectedIndex: _controller.index,
),
This is such a great feature, any updates to this? Thanks!
It is indeed... Especially because I am not able to implement that manually due to the fact that this assert will always fail if you try to connect the navigatorKeys (https://github.com/BilalShahid13/PersistentBottomNavBar/issues/210)... Does anyone know when this package will be updated? Or are there any forks of this package published to pub.dev that are still maintained?
This is implemented in the republished package persistent_bottom_nav_bar_v2 basically using your idea. This is needed for the onItemSelected function:
onItemSelected: (index) {
setState(() {
navBarEssentials.onItemSelected(index); // This also updates the controller index
});
}