Skip to content

[go_router] PopScope seems to be incompatible with GoRouter #138737

Open

Description

@btrautmann

Is there an existing issue for this?

Steps to reproduce

Original comment was made at #138525 (comment) but I'm pasting here:

[...] our team was investigating PopScope and found some interesting behavior that can be reproduced using this repo. I don't believe this component is behaving as described in the docs.

Using GoRouter APIs on iOS 17:

  1. When canPop is set to true, user can go back via app bar or back button but onPopInvoked is never invoked.
  2. When canPop is set to false, user cannot go back via app bar or back button but again onPopInvoked is only invoked with didPop set to false when pressing app bar back button. It is not invoked for the back gesture.

Using GoRouter APIs on Android 14:

  1. When canPop is set to true, user can go back via app bar or back button but onPopInvoked is never invoked.
  2. When canPop is set to false, user cannot go back via app bar or back button. onPopInvoked is invoked in both cases with didPop set to false.

Summary Table:

NOTE: For clarity, please note that for each column with onPopInvoked in the title, the true or false in the rows associated with that column indicate whether or not the onPopInvoked callback was invoked. This column is NOT intended to indicate anything about the didPop value, which is always (AFAIK) correct.

Platform Nav API canPop onPopInvoked(appBar) onPopInvoked (back swipe) onPopInvoked (Physical button) Expected behavior?
iOS GoRouter true false false --- false
iOS GoRouter false true false --- false
Android GoRouter true false false false false
Android GoRouter false true true true true

Expected results

The component should behave as described in the docs.

Actual results

See the table in the Steps to reproduce section.

Code sample

Code can be found in this repo.

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.16.0, on macOS 13.6.1 22G313 darwin-arm64, locale en-US)
    • Flutter version 3.16.0 on channel stable at /Users/brandontrautmann/fvm/versions/3.16.0
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db7ef5bf9f (2 days ago), 2023-11-15 11:25:44 -0800
    • Engine revision 74d16627b9
    • Dart version 3.2.0
    • DevTools version 2.28.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/brandontrautmann/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • ANDROID_SDK_ROOT = /Users/brandontrautmann/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode_14.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Community Edition (version 2023.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

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

[✓] Connected device (4 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android 13 (API 33) (emulator)
    • iPhone 13 mini (mobile)     • 0492C672-A151-402C-AAA0-0B694038CF37 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)             • macos                                • darwin-arm64   • macOS 13.6.1 22G313 darwin-arm64
    • Chrome (web)                • chrome                               • web-javascript • Google Chrome 119.0.6045.159

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. dam-ease commented on Nov 21, 2023

    @dam-ease

    Thanks for filing this and the detailed explanation.
    I can reproduce this on the latest master and stable channels.

    stable, master flutter doctor -v

    [!] Flutter (Channel stable, 3.16.0, on macOS 14.0 23A344 darwin-arm64, locale
        en-NG)
        • Flutter version 3.16.0 on channel stable at
          /Users/damilolaalimi/sdks/flutter
        ! Warning: `dart` on your path resolves to
          /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/damilolaalimi/sdks/flutter.
          Consider adding /Users/damilolaalimi/sdks/flutter/bin to the front of your
          path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision db7ef5bf9f (5 days ago), 2023-11-15 11:25:44 -0800
        • Engine revision 74d16627b9
        • Dart version 3.2.0
        • DevTools version 2.28.2
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android
          Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15A507
        • CocoaPods version 1.12.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio
          Preview.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build
          17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.84.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.50.0
    
    [✓] VS Code (version 1.83.1)
        • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
        • Flutter extension version 3.50.0
    
    [✓] Connected device (5 available)
        • sdk gphone64 arm64 (mobile) • emulator-5554                        •
          android-arm64  • Android 14 (API 34) (emulator)
        • Damilola’s iPhone (mobile)  • 00008110-001964480AE1801E            • ios
          • iOS 17.1.1 21B91
        • iPhone 15 (mobile)          • F17D2919-6D61-4295-8408-1719692FE958 • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
        • macOS (desktop)             • macos                                •
          darwin-arm64   • macOS 14.0 23A344 darwin-arm64
        • Chrome (web)                • chrome                               •
          web-javascript • Google Chrome 119.0.6045.159
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
    
    [!] Flutter (Channel master, 3.17.0-12.0.pre.39, on macOS 14.0 23A344 darwin-arm64, locale en-NG)
        • Flutter version 3.17.0-12.0.pre.39 on channel master at /Users/damilolaalimi/fvm/versions/master
        ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/damilolaalimi/fvm/versions/master. Consider adding /Users/damilolaalimi/fvm/versions/master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision b6ef78e955 (2 hours ago), 2023-11-20 23:37:25 -0500
        • Engine revision 70b1c73412
        • Dart version 3.3.0 (build 3.3.0-152.0.dev)
        • DevTools version 2.30.0-dev.4
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15A507
        • CocoaPods version 1.12.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio Preview.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.84.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.50.0
    
    [✓] VS Code (version 1.83.1)
        • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
        • Flutter extension version 3.50.0
    
    [✓] Connected device (5 available)
        • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android 14 (API 34) (emulator)
        • Damilola’s iPhone (mobile)  • 00008110-001964480AE1801E            • ios            • iOS 17.1.1 21B91
        • iPhone 15 (mobile)          • F17D2919-6D61-4295-8408-1719692FE958 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
        • macOS (desktop)             • macos                                • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
        • Chrome (web)                • chrome                               • web-javascript • Google Chrome 119.0.6045.159
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
    

  2. added
    packageflutter/packages repository. See also p: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Nov 21, 2023
  3. chunhtai commented on Nov 30, 2023

    @chunhtai
    Contributor

    I am actively working on this. It will have to wait for #137792 before I can fix this issue

  4. self-assigned this
    on Nov 30, 2023
  5. RioChndr commented on Dec 24, 2023

    @RioChndr

    Hi @btrautmann. I look into your reproduce_repo. I see you use go instead push, I wonder why you use this method. It would be nice if popScope could trigger the onPopInvoked. I also create Reproduce Repo that use go and push to test it.

  6. btrautmann commented on Dec 26, 2023

    @btrautmann
    Author

    I look into your reproduce_repo. I see you use go instead push, I wonder why you use this method.

    Our team uses go pretty much everywhere because it's idempotent (i.e you can invoke a go call 100x and you will have the same result as if you invoked it just once). This is not true of push and can lead to navigation issues. There are obviously use cases for push but IMO it shouldn't be the default.

    Edit: Just to clarify, my usage of go in the repro was simply habit, I didn't intend it to influence the filed issue behavior at all.

  7. 95 remaining items

  8. Gustl22 commented on Jun 19, 2025

    @Gustl22
    Contributor

    go_router with the fix was released in >=15.2.3.
    Is anyone experiencing further issues? Otherwise this probably can be closed.

  9. Gustl22 commented on Jun 30, 2025

    @Gustl22
    Contributor

    @btrautmann I guess this can be closed, as its fixed ^^

  10. juampiq6 commented on Jul 1, 2025

    @juampiq6

    @Gustl22 i was investigating related issues and ran into this one, can my issue #171451 have something to do with this one?

    Edit: I already tried with latests 15.2.4 version and my issue can still be reproduced

  11. changed the title [-]PopScope seems to be incompatible with GoRouter[/-] [+][go_router] PopScope seems to be incompatible with GoRouter[/+] on Jul 29, 2025
  12. TheManuz commented on Oct 2, 2025

    @TheManuz

    go_router with the fix was released in >=15.2.3. Is anyone experiencing further issues? Otherwise this probably can be closed.

    Yep, sadly GoRouter doesn't respect PopScope widget with canPop: false.

    The result is that onPopInvokedWithResult will be called (as expected) with a true didPop (expected false).

    Tried this on go_router: 16.2.1

    EDIT: tested on go_router: 15.1.3, same behavior

  13. added
    P2Important issues not at the top of the work list
    and removed
    P1High-priority issues at the top of the work list
    on Nov 5, 2025
  14. kerimamansaryyev commented on Dec 17, 2025

    @kerimamansaryyev

    @Gustl22 @chunhtai

    I investigated behavior of PopScope that is used in routes under StatefulShellRoute, or a widget wrapping the navigation container of the StatefulShellRoute. I intended to implement a use-case where the app is prevented from closing when the tab view (the indexed stack incorporated by StatefulShellRoute.indexedStack) was focused on any tab except the Home tab (at index 0), and a user would be navigated to the Home tab afterwards.

    I wrapped a widget (the shell) containing the tab view with PopScope and assigned the logic, however, behavior of the PopScope was very flaky, sometimes it would work, sometimes the app would be closed. Upon investigation, I found out that the flaky behavior of PopScope is correlated with the Android Predictive Back feature. When I turned that off by adding android:enableOnBackInvokedCallback="false" into the application tag of AndroidManifest.xml, PopScope did indeed prevent closing the app.

    From my understanding, although the predictive back feature requires canPop to be available ahead of time, the feature is not supposed to ignore it, is it? Because otherwise it wouldn't let developers reliably implement navigation prevention mechanisms like, for example, confirmation dialogs.

  15. Gustl22 commented on Dec 17, 2025

    @Gustl22
    Contributor

    @kerimamansaryyev I personally also experienced problems with predictive back gesture like in #152323. But that exceeds the scope of this issue. We ended up disabling it (until it works).

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

    P2Important issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.found in release: 3.16Found to occur in 3.16found in release: 3.17Found to occur in 3.17has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions