While implementing persistent bottom bar, previous route need to be restored when a button in the bottom bar was clicked.
When a button in the bottom bar is clicked, its current route path (/a/b/c) is saved and previously saved route is restored according to the button click.
Conceptually user will think each button as a workspace and its state is never get lost (including back stack). User can safely switch from one workspace to another.
How to get current route path in Flutter, when the routing is rewinding to root?
NavigatorState
doesn't expose an API for getting the path of the current route, andRoute
doesn't expose an API for determining a route's path either. Routes can be (and often are) anonymous. You can find out if a givenRoute
is on the top of the navigator stack right now using theisCurrent
method, but this isn't very convenient for your use case.I would recommend that you take a different approach to this problem and don't rewind to the root at all. Instead, use a different
Navigator
widget for each pane of theBottomNavigationBar
. That way, you won't have to rewind the stack when switching between panes. You can wrap yourNavigator
widgets inOpacity
andIgnorePointer
widgets to hide them when they aren't supposed to be visible without destroying their stack.