auto_route_library
auto_route_library copied to clipboard
Not able to push page after using AutoRouterDelegate.declarative
I am not able to push a new Page when using AutoRouterDelegate.declarative
instead of _appRouter.delegate()
as routerDelegate, described here auto_route auth.
Router:
MaterialApp.router(
debugShowCheckedModeBanner: false,
//routerDelegate: _appRouter.delegate(),
routerDelegate: AutoRouterDelegate.declarative(
_appRouter,
routes: (_) => [
if (authState)
const MyHomeRouter()
else
const AuthRouter(),
],
),
routeInformationParser: _appRouter.defaultRouteParser(includePrefixMatches: true),
)
router.dart
@MaterialAutoRouter(
replaceInRouteName: 'Page,Route',
routes: <AutoRoute>[
AutoRoute(
page: MyHomePage,
name: "MyHomeRouter",
initial: true,
children: [
AutoRoute(
page: HomePage,
path: "home",
name: "HomeRouter",
),
AutoRoute(page: NotificationPage, path: "notification"),
],
),
AutoRoute(
page: LoginPage,
path: "/auth",
name: "AuthRouter",
children: [
AutoRoute(page: SignupPage, path: "signup"),
],
),
],
)
class $AppRouter {}
When using routerDelegate: _appRouter.delegate()
I am able to push to new page like context.router.pushNamed("/notification")
. After using AutoRouterDelegate.declarative
I get this error when trying to push to new page
Unhandled Exception: 'package:auto_route/src/router/controller/routing_controller.dart': Failed assertion: line 861 pos 7: '!managedByWidget': Pages stack can be managed by either the Widget (AutoRouter.declarative) or Router
Why is it not possible to push new page when using declarative approach?
@combi-35 you should be able to push to MyHomeRouter
not the root router.
what widget are you pushing from?
Hi @Milad-Akarie, how would I do that?
I am pushing from onPressed action
IconButton(
icon: const Icon(Icons.notifications),
onPressed: () => context.router.pushNamed("/notification")
)
@combi-35 what screen/route are you pushing from? I need to know hierarchy
@Milad-Akarie I am pushing from HomePage
to NotificationPage
.
MyHomePage
is root router with BottomNavigationBar
, it contains HomePage
and NotificationPage
.
PushNamd('notification') without forward slash
Or use navigateNamed
context.router.pushNamed('notification')
throws an error
context.navigateNamedTo('notification')
is working
But what happens in first place? It was working with context.router.pushNamed('notification')
when I used routerDelegate: _appRouter.delegate()
.
@combi-35 obviously you're not obtaining the right router.
@Milad-Akarie can you please elaborate or provide an example on how to actually move across screens within routers that have been added with AutoRouterDelegate.declarative?
I also keep getting errors saying that I can't push when routes because the router is declarative.
Same scenario as @combi-35
Mind you, I'm not pushing to Root. If I do print(context.router.current.name)
, it prints AuthRouter
. and context.router.current.parent?.name
is Root
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
Still waiting on this
getting the same error when using the declarative auth...
[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: 'package:auto_route/src/router/controller/routing_controller.dart': Failed assertion: line 1095 pos 7: '!managedByWidget': Pages stack can be managed by either the Widget (AutoRouter.declarative) or Router
Same here
Has anyone solved this issue yet?
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
Not stale. Still waiting
This is not a bug, it's an intended behavior. Pages stack can only be managed by widget or push pop and friends Can't managed by both in the same controller
On Sun, Nov 13, 2022, 7:42 PM Jose Tapizquent @.***> wrote:
Not stale. Still waiting
— Reply to this email directly, view it on GitHub https://github.com/Milad-Akarie/auto_route_library/issues/721#issuecomment-1312772466, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANECH6KESG3CYAZLXCNXDPDWIEK6LANCNFSM5EYWRMRA . You are receiving this because you were mentioned.Message ID: @.***>
@Milad-Akarie thank you so much for replying. I guess in that case what we need is maybe more examples on how to achieve the same or a similar behavior.
I'm trying to squeeze sometime for auto_route hopefully in the near future will be more examples
@combi-35 obviously you're not obtaining the right router.
@Milad-Akarie Could you please elaborate on this? One line of code or a link to some related docs would help us a lot.
Thanks for your efforts