Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Support MaterialApp.router() which doesn't have a navigatorKey argument, as well as MaterialApp() #197

Open
buzzware opened this issue Oct 20, 2021 · 6 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@buzzware
Copy link

Is your feature request related to a problem? Please describe.
Your documentation says to include navigatorKey: Catcher.navigatorKey when calling MaterialApp().
Navigator 2.0 uses MaterialApp.router instead, which doesn't have a navigatorKey parameter,
and then I get the error "Couldn't use report mode because you didn't provide navigator key. Add navigator key to use this report mode."

Describe the solution you'd like
I don't know enough about keys or this library to suggest a solution

Describe alternatives you've considered
Maybe create my own version of MaterialApp.router ?

Additional context
Add any other context or screenshots about the feature request here.

@buzzware buzzware added enhancement New feature or request New issue New issue which has not been checked yet labels Oct 20, 2021
@buzzware
Copy link
Author

The issue occurs with DialogReportMode. Using SilentReportMode instead seems to resolve it.

@jhomlala
Copy link
Owner

jhomlala commented Nov 7, 2021

@buzzware Navigator key has been used for 1.0 routing. I didn't use 2.0 yet because level of complexity (there's even package created by one of flutter team members to handle this complexity). Can you provide some minimal reproducible example? It could be just small two screens app.

@jhomlala jhomlala added help wanted Extra attention is needed and removed enhancement New feature or request New issue New issue which has not been checked yet labels Nov 7, 2021
@mikeesouth
Copy link

@jhomlala I agree that the 2.0 routing is a mess from Flutters side, at least earlier this year when I implemented it in our app. This is a pretty good article and there are some others too: https://johnwcassidy.medium.com/building-a-simple-stack-navigator-with-flutter-navigation-2-0-f11b55b71520
That article has the source code for the navigator 2.0 sample here: https://github.com/bigbluewhaledev/flutter_navigation_2_0

I'm using catcher with navigator 2.0 by adding the Catcher.navigatorKey to the "Navigator" widget, like this:
final navigatorKey = Catcher.navigatorKey ?? GlobalKey<NavigatorState>();

And then I set it in the Navigator class like this:

return Navigator(
  key: navigatorKey,
  pages: [...],
  ....,
);

I'm just adding catcher to this project but it seems to work very nicely.

@buzzware see above if you haven't found a workaround yet.

@ibrahim-mubarak
Copy link

I think that the larger issue here is some routing libraries are managing their own navigator keys.
As catcher is usually initialised very early on in the App setup, and the routers are probably initialised in the runAppFunction or rootWidget section of catcher, there is no place where a navigator key can be setup.

I think this can be mitigated by either the navigator libraries allowing us to provide a Key
or Catcher allowing us to provide a Navigator key later on in the App Setup cycle

Just through a quick skim,
VRouter, Auto Route, Flutter Modular allow setting a NavigatorKey
Go Router and Beamer do not

@rivella50
Copy link

@ibrahim-mubarak So is there another way to set the value for navigatorKey?
I would like to use Beamer but do not see a way to apply GlobalKey<NavigatorState>.

@fredgrott
Copy link
Contributor

For Go Router in your GoRouter constructor you can set a navigationKey so that is the place to put the Catcher.naviationKey as far as I know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants