Reputation: 607
While I'm searching for a solution to navigate to some widget without context (my use case involves navigating to a widget onNotificationClick events). I found a solution to create a GlobalKey<NavigatorState>()
and use it with MaterialApps
navigatorKey
property to navigate wherever I want.
It is working well for me, however recently I came across some comments in SO where it is said not to use this way because global keys are expensive but I couldn't find a complete answer to this question. So, is it really a bad practice, what can be an alternate solution?
Upvotes: 0
Views: 327
Reputation: 137
Flutter 1.22 introduced Navigator 2.0, a new declarative API that allows you to take full control of your navigation stack
Exposing the navigator’s page stack: You can now manage your pages
Backward-compatible with imperative API: You can use both imperative and declarative styles in the same app.
Handle operating system events: Works better with events like the Android system’s Back button.
Router( routerDelegate: _appRouter, backButtonDispatcher: RootBackButtonDispatcher(), )),
Manage nested navigators: Gives you control over which navigator has priority.
Manage navigation state: Lets you parse routes and handles web URLs and deep linking
Upvotes: 0