Closed Fiyiin closed 3 years ago
Hey @Fiyiin , how are you pushing the routes? Where are you pushing from and where are you pushing to?
A resource that might be valuable is: https://github.com/flutter/uxr/blob/master/nav2-usability/scenario_code/lib/sign-in-routing/sign_in_routing_auto_route.dart
It uses the AutoRouterDelegate.declarative for auth, and it also works when pushing routes
@theweiweiway from the Login screen to the SignUp screen, I use context.router.push(SignUpRoute)
. That's where I get the error, when using AutoRouterDelegate.declarative
Ah i see. You have 3 distinct routers at the root level:
LoginScreen router SignUpScreen router NavigationHandlerScreen router
but your routing declaration only has 2:
if (AppModel().isLoggedIn)
NavigationHandlerRoute()
else
LoginRoute()
you're trying to go from LoginScreen to SignUpScreen but SignUpScreen is not declared in the delegate. What you will need to do is:
@AdaptiveAutoRouter(
replaceInRouteName: 'Screen,Route',
routes: <AutoRoute>[
// notice how combine login and sign-up into one nested page
AutoRoute(page: EmptyRouterPage, path: '/auth',
name: 'AuthRouter',
children: [
AutoRoute(page: LoginScreen, path: 'login'),
AutoRoute(page: SignUpScreen, path: 'sign-up'),
]),
AutoRoute(
path: '/',
page: NavigationHandlerScreen,
children: [
AutoRoute(
path: 'home',
name: 'HomeRouter',
page: EmptyRouterPage,
children: [AutoRoute(path: '', page: HomeScreen)],
),
AutoRoute(
path: 'notifications',
name: 'NotificationsRouter',
page: EmptyRouterPage,
children: [AutoRoute(path: '', page: NotificationsScreen)],
),
AutoRoute(
path: 'watching',
name: 'WatchingRouter',
page: EmptyRouterPage,
children: [AutoRoute(path: '', page: WatchingScreen)],
),
AutoRoute(
path: 'partners',
name: 'PartnersRouter',
page: EmptyRouterPage,
children: [AutoRoute(path: '', page: PartnersScreen)],
)
],
)
],
)
Now, you can do
if (AppModel().isLoggedIn)
NavigationHandlerRoute()
else
AuthRouter()
Now login and sign-up are both exposed in the delegate, instead of just the login page
thanks a lot @theweiweiway worked with a little modification AutoRoute(page: LoginScreen, path: 'login', initial: true),
I've got the same problem. I tried to change the parents into the Router, but the issue is still there. Any adivce ?
I'm following the authentication example in the docs. The problem is that when I try to push from any of the routes I get this error
_AssertionError ('package:auto_route/src/router/controller/routing_controller.dart': Failed assertion: line 696 pos 7: '!managedByWidget': Pages stack can be managed by either the Widget (AutoRouter.declarative) or the (StackRouter))
This is my MaterialApp.router
Router