Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

handle alt+rightArrow or alt+leftArrow keys to navigate back and forth in the current history stack #267

Closed
csells opened this issue Dec 23, 2021 Discussed in #212 · 1 comment
Labels
enhancement New feature or request

Comments

@csells
Copy link
Owner

csells commented Dec 23, 2021

Discussed in #212

Originally posted by Agondev November 25, 2021
By wrapping the MaterialApp's builder's child with CallbackShortcut and passing various options of popping route, like

Navigator.of(context)

or

context.pop()

or

GoRouterDelegate

or

_goRouter.pop()

or

Router.of(context).routerDelegate.popRoute()

etc.

I get exceptions like

Router operation requested with a context that does not include a Router.

and

No GoRouter found in context.

Only thing that seems to kind of work is appRouter.navigator?.pop(), and that requires 2 attempts after the first time. With Auto Route it's enough to call _autoRoute.pop() from anywhere in the app using a shortcut of my choosing for it to pop the closest encompassing route.

Can the same not be done in GoRouter?

Example of my latest draft of MaterialApp

return MaterialApp.router(
  routeInformationParser: _router.routeInformationParser,
  routerDelegate: _router.routerDelegate,
  builder: (context, child) {
    CallbackShortcuts(
        bindings: {
          LogicalKeySet(
                    LogicalKeyboardKey.escape,
                  ): () => appRouter.navigator?.pop(),
                    LogicalKeyboardKey.escape,
                    LogicalKeyboardKey.alt,
                  ): () => appRouter.pop(), // or context.pop()
        }
        child: child!,
    )
  }
);

To reiterate, the first binding works in GoRouter after two attempts, the second one just throws. But it does work in Auto Route with no problems.

@csells csells added the enhancement New feature or request label Dec 23, 2021
@csells
Copy link
Owner Author

csells commented Dec 23, 2021

More details here: #212 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant