PersistentBottomNavBar icon indicating copy to clipboard operation
PersistentBottomNavBar copied to clipboard

Add popAllScreensForTheSelectedTab functionality for custom navbar

Open sieg-fred opened this issue 4 years ago • 3 comments
trafficstars

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) customWidget exposing NavBarEssentials
  • Added bool popAllScreensOnTapOfSelectedTab = true and List<PersistentBottomNavBarItem> items in PersistentBottomNavBarItem.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,
        ),

sieg-fred avatar Apr 11 '21 10:04 sieg-fred

This is such a great feature, any updates to this? Thanks!

kirkcharlesniv avatar May 04 '21 13:05 kirkcharlesniv

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?

jb3rndt avatar Jan 07 '22 10:01 jb3rndt

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
    });
}

jb3rndt avatar Jan 20 '22 14:01 jb3rndt