auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

Not able to push page after using AutoRouterDelegate.declarative

Open combi-35 opened this issue 3 years ago • 14 comments

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 avatar Sep 26 '21 11:09 combi-35

@combi-35 you should be able to push to MyHomeRouter not the root router. what widget are you pushing from?

Milad-Akarie avatar Sep 26 '21 12:09 Milad-Akarie

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 avatar Sep 26 '21 14:09 combi-35

@combi-35 what screen/route are you pushing from? I need to know hierarchy

Milad-Akarie avatar Sep 26 '21 15:09 Milad-Akarie

@Milad-Akarie I am pushing from HomePage to NotificationPage. MyHomePage is root router with BottomNavigationBar, it contains HomePage and NotificationPage.

combi-35 avatar Sep 26 '21 15:09 combi-35

PushNamd('notification') without forward slash

Milad-Akarie avatar Sep 26 '21 15:09 Milad-Akarie

Or use navigateNamed

Milad-Akarie avatar Sep 26 '21 15:09 Milad-Akarie

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 avatar Sep 26 '21 15:09 combi-35

@combi-35 obviously you're not obtaining the right router.

Milad-Akarie avatar Sep 28 '21 08:09 Milad-Akarie

@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

tapizquent avatar Jan 13 '22 02:01 tapizquent

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

github-actions[bot] avatar Aug 01 '22 08:08 github-actions[bot]

Still waiting on this

tapizquent avatar Aug 01 '22 11:08 tapizquent

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

gabsn avatar Sep 05 '22 17:09 gabsn

Same here

soliev01 avatar Sep 14 '22 02:09 soliev01

Has anyone solved this issue yet?

soliev01 avatar Sep 14 '22 02:09 soliev01

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

github-actions[bot] avatar Nov 13 '22 08:11 github-actions[bot]

Not stale. Still waiting

tapizquent avatar Nov 13 '22 16:11 tapizquent

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 avatar Nov 13 '22 16:11 Milad-Akarie

@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.

tapizquent avatar Nov 13 '22 17:11 tapizquent

I'm trying to squeeze sometime for auto_route hopefully in the near future will be more examples

Milad-Akarie avatar Nov 13 '22 19:11 Milad-Akarie

@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

SharbelOkzan avatar Dec 08 '22 20:12 SharbelOkzan