Milad-Akarie / auto_route_library

Flutter route generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Persistent navigation bar across all pages

MadsVETiSearch opened this issue · comments

Ive set up my routes like this:

@AdaptiveAutoRouter( replaceInRouteName: 'Page,Route', routes: <AutoRoute>[ AutoRoute(page: LoadingPage, initial: true), AutoRoute( page: LoginPage, children: [ RedirectRoute(path: '*', redirectTo: ''), ], ), AutoRoute( path: '/', page: RootPage, children: [ AutoRoute( path: 'nye_produkter', name: 'NewProductsRouter', page: NewProductsPage, ), AutoRoute( path: 'recepter', name: 'PrescriptionsRouter', page: PrescriptionPage, ), AutoRoute( path: 'hjem', name: 'HomeRouter', page: HomePage, initial: true, ), AutoRoute( path: 'lister', name: 'ListsRouter', page: ClinicMedicinListsPage, ), AutoRoute( path: 'menu', name: 'MenuRouter', page: MenuPage, ), ], ), AutoRoute( path: 'settings', name: 'SettingsRouter', page: SettingsPage, children: [ AutoRoute( name: "StandardSpeciesRouter", page: StandardSpeciesPage, ), AutoRoute( name: 'UpdatePasswordRouter', page: UpdatePasswordPage, ), AutoRoute( name: 'UpdateProfilePictureRouter', page: UpdateProfilePicturePage, ), AutoRoute( name: 'UpdateSignatureRouter', page: UpdateSignaturePage, ), AutoRoute( name: 'UpdateUserInformationRouter', page: UpdateUserInformationPage, ), ], ) ], )

And the navigationbar works just fine, but when i navigate to Settings, the nav bar disappears, and that is because settings isnt nested within the root page, but when i do that and navigate to settings, i get the following error message Looks like you're trying to navigate to a nested route without adding their parent to stack first

is there any way to persist the navigation bar no matter which route i navigate to?

@MadsVETiSearch You just need to push whatever parent route SettingsRoute is a child of.
navigateTo(ParentRoute(children: [SettingsRoute()]);

@Milad-Akarie First of all, thanks for the quick reply!
I have another questiong, is it possible to keep navigation bar persistent and only push the screens to the body of the autotabscaffold?

Sure, but each tab will have it's own stack

I am having a similar issue, could not figure out how to give more children to my HomeRoute apart from the ones it has in the BottomNavBar.

This is a simplified version of my setup:

AutoRoute(
        path: '/home',
        page: HomeView,
        name: 'HomeRoute',
        initial: false,
        children: [
          AutoRoute(
            path: ':content',
            name: 'ContentRoute',
            page: ContentView,
          ),
          AutoRoute(
            path: 'new',
            name: 'NewPostRoute',
            page: NewPostView,
          ),
          AutoRoute(
            path: 'explore',
            name: 'ExploreRoute',
            page: ExploreView,
          ),
])

There are BottomNavBar items on the HomeView. I can navigate to my ExploreView, and I want to go to my ContentView in the ExploreView, the BottomNavBar persisting.
The following doesn't work:

context.router.navigate(HomeRoute(
                children: [ContentRoute(content: content)],
              ));

But if I do the following when I am in the NewPostView, I go to ExploreView:

context.router.navigate(HomeRoute(
                children: [ExploreRoute()],
              ));

How can I go to the ContentView from my ExploreView, my BottomNavBar still persisting? Should I add my ContentRoute as a child to my ExploreRoute instead?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions