Skip to content

Duplicate GlobalKey when using the Navigator #33116

@larssn

Description

@larssn

Simple use case

On each named route in your app, you have a single Scaffold that contains a given static GlobalKey, so no matter which route you land on, you can access that given Scaffold using said GlobalKey (relevant for showing snackbars for example).

However when navigating using named routes, flutter throws the "Duplicate GlobalKey" error.

Steps to Reproduce

I've made an extremely simple example of the problem, using two named routes, that navigate to the same Scaffold that shows the counter from the default flutter project.

  1. git clone github.com/larssn/flutter-globalkey-navigator
  2. flutter run
  3. Click either the "Route1" or "Route2" button.

Duplicate GlobalKey error happens.

(Navigation looks like this: https://github.com/larssn/flutter-globalkey-navigator/blob/master/lib/main.dart#L115)

Logs

Logs probably aren't relevant, but let me know if you want them.
Analyzing navtest...
No issues found! (ran in 5.9s)
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.13.6 17G6030, locale en-DK)
    • Flutter version 1.5.4-hotfix.2 at /Users/larsstoettrup/workspace/flutter
    • Framework revision 7a4c33425d (3 weeks ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/larsstoettrup/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/larsstoettrup/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.4
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 35.3.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.34.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.0.2

[✓] Connected device (1 available)
    • SM T580 • 52037c6b4d72c351 • android-arm • Android 8.1.0 (API 27)

Metadata

Metadata

Assignees

No one assigned

    Labels

    frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions