-
-
Notifications
You must be signed in to change notification settings - Fork 29
Support go_router
/ MaterialApp.router(…)
#48
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
Support go_router
/ MaterialApp.router(…)
#48
Conversation
…er `runApp` was called. This allows combining `go_router` / `MaterialApp.router` with the `DialogReportMode`.
Thanks for the PR - however, I am not quite sure whether I understand the current limitations. void main() {
final _router = GoRouter(...);
[...other setup for catcher_2...]
Catcher2(rootWidget: MyApp(), debugConfig: debugOptions, releaseConfig: releaseOptions,
navigatorKey: _router.routerDelegate.navigatorKey); // this line right here
} |
Yes, this would be possible, however there is another limitation. But imagine the following scenario: You want to display a loading screen / sign in screen first, but catch errors with loading / sign in with See this example: void main() {
// [...other setup for catcher_2...]
Catcher2(rootWidget: MyLoader(), debugConfig: debugOptions, releaseConfig: releaseOptions); // <-- cannot access `GoRouter` instance here, because it is created later
}
class MyLoader extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: …, // <-- do some async loading call here, maybe even sign-in
builder: (context, snapshot) {
if (snapshot.hasData) {
return MyApp(isAdmin: snapshot.requireData.isAdmin); // launch the main app when future has completed
}
return Loader(); // show loader until future completes and we can launch the main app
},
);
}
}
class MyApp extends StatelessWidget {
const MyApp({required this.isAdmin});
final bool isAdmin;
@override
Widget build(BuildContext context) {
final goRouter = GoRouter(
routes: [
GoRoute("/home", …),
if (isAdmin) GoRoute("/admin", …), // <-- this depends on the result of the loading call, however, I want to show a loading screen and have `Catcher2` catch loading errors before
],
);
return MaterialApp.router(
router: goRouter;
);
}
} |
Ah, I see. Indeed, that's an interesting use case to cover. I believe, the best way to avoid duplicate code and the like would be to just rename the |
Yes, making |
Thank you very much! I like that - making the field non- |
Thanks once again! I will publish this now as part of 2.1.3! |
* Exposed `configureNavigatorKey` to update the used `navigatorKey` after `runApp` was called. This allows combining `go_router` / `MaterialApp.router` with the `DialogReportMode`. * Refactored to remove abstractions.
Fixes #47
This allows combining
go_router
/MaterialApp.router(…)
with theDialogReportMode
.It is achieved by exposing the
_configureNavigatorKey
instance method ofCatcher2
publicly to enable updating the usednavigatorKey
afterrunApp
was called.Now users can call: