Repository navigation
Add NavigationKey in GoRouter #109479
Description
Steps to Reproduce
I am using the go_router in my app and also the get package. The problem is that since I implemented the Go-Router I can no longer show the Get.snackbar. It is failing and throwing a null-error.
For the GoRouter to work I had to add the .router for my GetMaterialApp. And then navigationKey was no longer available:
This is my GetMaterialApp:
child: GetMaterialApp.router(
title: 'Wishlists',
// navigationKey: Get.key,
// .router does not have a navigationKey so showSnackBar fails because the key is null
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
translationsKeys: AppTranslation.translationsKeys,
locale: locale,
fallbackLocale: fallbackLocale,
),
This is the error:
Error: Unexpected null value.
at Object.throw_ [as throw] (http://localhost:51492/dart_sdk.js:5080:11)
at Object.nullCheck (http://localhost:51492/dart_sdk.js:5399:30)
at [_configureOverlay] (http://localhost:51492/packages/get/get_navigation/src/snackbar/snackbar_controller.dart.lib.js:2970:53)
at [_show] (http://localhost:51492/packages/get/get_navigation/src/snackbar/snackbar_controller.dart.lib.js:3113:30)
I feel like it has something to do with the key inside the GetMaterialApp, but I have no idea how to solve this.
Is this a known bug? What am I missing here?
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
iapicca commentedon Aug 13, 2022
being able to customize go_router is generally good, so I'm supportive of the idea
especially when it seems to be an
easy fixGoRouter({ /// ... + GlobalKey<NavigatorState>? key, }) { /// ... _routerDelegate = GoRouterDelegate( + key: key, ); /// ... }GoRouterDelegate({ /// ... + GlobalKey<NavigatorState>? key, }) : builder = RouteBuilder( /// ... - ); + ), + _key = key ?? GlobalKey<NavigatorState>(); /// ... + final GlobalKey<NavigatorState> _key; - final GlobalKey<NavigatorState> _key = GlobalKey<NavigatorState>();Nonetheless this is yet another example of why devs should steer clear of getX!
something as easy as display a snackbar
being "vendor locked" is just bad (together with many other reasons, including fudged benchmarks)
[-]NavigationKey in GoRouter[/-][+]Add NavigationKey in GoRouter[/+]exaby73 commentedon Aug 15, 2022
Hello @DieGlueckswurst. Thanks for filing this request. Looks like a valid one. Labelling as such.
chunhtai commentedon Aug 18, 2022
The pr flutter/packages#2453 (comment) adds the navigator key to gorouter
rddewan commentedon Aug 22, 2022
Yes please we need this to be able to navigate with Firebase push notification click listener , with GoRouter we are not able to get the context to navigate
DieGlueckswurst commentedon Sep 13, 2022
any updates on this? seems like a quick fix. would help me a lot :D
github-actions commentedon Sep 30, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.