csells / go_router

The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
https://gorouter.dev
441 stars 96 forks source link

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

Closed csells closed 2 years ago

csells commented 2 years ago

Discussed in https://github.com/csells/go_router/discussions/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 ```dart 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 commented 2 years ago

More details here: https://github.com/csells/go_router/discussions/212#discussioncomment-1745721