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

navigatorKey.currentState.push equivalent #257

Closed RaduGrama closed 2 years ago

RaduGrama commented 2 years ago

Is there a navigatorKey.currentState.push() equivalent in go_router for scenarios where navigation is triggered from Redux middleware for example? With navigatorKey defined as final navigatorKey = GlobalKey<NavigatorState>();

csells commented 2 years ago

what problem are you trying to solve?

RaduGrama commented 2 years ago

I use Redux for state management and I have epics that handle certain Redux actions, where a context is not available. When I initialize each epic, I pass in the global navigatorKey and then from epics I can call navigatorKey.currentState.push() to push a new screen.

I think I answered my own question by using code like:

final router = GoRouter(routes: [ /* routes */ ]);
final navigatorKey = router.routerDelegate.navigatorKey;

// original code
csells commented 2 years ago

And did that do the trick?