Skip to content

Conversation

@sieg-fred
Copy link

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

@kirkcharlesniv
Copy link

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

@jb3rndt
Copy link

jb3rndt commented Jan 7, 2022

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 (#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
Copy link

jb3rndt commented Jan 20, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants