Skip to content

Add NavigationKey in GoRouter #109479

Closed
flutter/packages
#2453

Description

@DieGlueckswurst

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?

Activity

  1. iapicca commented on Aug 13, 2022

    @iapicca

    being able to customize go_router is generally good, so I'm supportive of the idea
    especially when it seems to be an easy fix

      GoRouter({
        /// ...
    +  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

    ScaffoldMessenger.of(context).showSnackBar(snackBar);

    being "vendor locked" is just bad (together with many other reasons, including fudged benchmarks)

  2. added
    in triagePresently being triaged by the triage team
    on Aug 15, 2022
  3. changed the title [-]NavigationKey in GoRouter[/-] [+]Add NavigationKey in GoRouter[/+] on Aug 15, 2022
  4. exaby73 commented on Aug 15, 2022

    @exaby73
    Member

    Hello @DieGlueckswurst. Thanks for filing this request. Looks like a valid one. Labelling as such.

  5. added
    c: new featureNothing broken; request for a new capability
    packageflutter/packages repository. See also p: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Aug 15, 2022
  6. chunhtai commented on Aug 18, 2022

    @chunhtai
    Contributor

    The pr flutter/packages#2453 (comment) adds the navigator key to gorouter

  7. rddewan commented on Aug 22, 2022

    @rddewan

    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

  8. added
    P3Issues that are less important to the Flutter project
    on Aug 23, 2022
  9. DieGlueckswurst commented on Sep 13, 2022

    @DieGlueckswurst
    Author

    any updates on this? seems like a quick fix. would help me a lot :D

  10. moved this to Done in GoRouteron Sep 16, 2022
  11. added
    r: fixedIssue is closed as already fixed in a newer version
    on Sep 16, 2022
  12. github-actions commented on Sep 30, 2022

    @github-actions

    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 -v and a minimal reproduction of the issue.

  13. locked as resolved and limited conversation to collaborators on Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions