Repository navigation
PopScope does not invoke onPopInvoked for iOS back gesture when canPop set to false #138624
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
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 Navigator 1.0 APIs on iOS 17:
- When
canPopis set totrue, user can go back via app bar or back button andonPopInvokedis invoked withdidPopset totruein both cases. - When
canPopis set tofalse, user cannot go back via app bar or back button, butonPopInvokedis only invoked withdidPopset tofalsewhen pressing app bar back button. It is not invoked at all for the back gesture, which is unexpected per the docs (which read The [onPopInvoked] parameter reports when system back gestures occur, regardless of whether or not they were successful).
Using Navigator 1.0 APIs on Android 14:
- When
canPopis set totrue, user can go back via app bar or back button andonPopInvokedis invoked withdidPopset totruein both cases. - When
canPopis set tofalse, user cannot go back via app bar or back button, andonPopInvokedisinvokedin both cases withdidPopset tofalse
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 | 1.0 | true | true | true | --- | true |
| iOS | 1.0 | false | true | false | --- | false |
| Android | 1.0 | true | true | true | true | true |
| Android | 1.0 | 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
No response
Logs
No response
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
dam-ease commentedon Nov 20, 2023
Thanks for filing this and for the detailed explanation.
Testing with Nav API 1.0, I see the issue occurs only on the second row, where
canPopis set to false on iOS. Others seem to work as expected both on Android and iOS (kindly provide more information on this if my understanding of this is incorrect)For the second row as I referenced above, running the reproduction sample and testing with
canPopset to false, I can't seem to reproduceonPopInvoked(appBar)being true (logs below).Screen record
Screen.Recording.2023-11-20.at.13.39.22.mov
Can you confirm this on your end again as well?
I'd also suggest separating the issue with Nav API 1.0 from that reproduced with
go_routerso it's easier to track but if on confirmation of the one issue withNav API 1.0, if it doesn't persist, I guess we could retain this and triage the issues when usinggo_routerflutter doctor -v
btrautmann commentedon Nov 20, 2023
I'm sorry, this was a lack of clarity on my part. For each column that has
onPopInvoked, thetrueorfalseindicates whether or not the callback was invoked, not what thedidPopvalue actually was. As far as I recall, thedidPopvalue was always correct whenever the callback was actually invoked, as it is in your screen recording!Edit: I've added a clarification above the Summary Table in the description to (hopefully) clear up the intent of those columns.
[-]PopScope does not behave as expected in several situations[/-][+]PopScope does not invoked `onPopInvoked` for iOS back gesture when `canPop` set to false[/+]btrautmann commentedon Nov 20, 2023
As requested, I've opened #138737 which covers all GoRouter cases. I've narrowed the scope of this ticket as well as its description to capture the issue with Navigator 1.0 APIs.
[-]PopScope does not invoked `onPopInvoked` for iOS back gesture when `canPop` set to false[/-][+]PopScope does not invoke `onPopInvoked` for iOS back gesture when `canPop` set to false[/+]dam-ease commentedon Nov 21, 2023
Thanks for explaining further. I can reproduce this on the latest
masterandstable, channelsas also shown in the video at #138624 (comment).stable, master flutter doctor -v
67 remaining items
flutter-triage-bot commentedon Apr 1, 2025
This issue is assigned to @chunhtai but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!
flutter-triage-bot commentedon Jun 17, 2025
This issue was assigned to @chunhtai but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.
justinmc commentedon Jun 17, 2025
@chunhtai Is this still a P1? Do you plan to return to it?
flutter-triage-bot commentedon Oct 22, 2025
This issue is marked P1 but has had no recent status updates.
The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub.
Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks!
cristovaoFariasSmart commentedon Oct 31, 2025
this must be a P1, a lot of companies are doing workarounds to make swipeback work properly becasue of that
caseycrogers commentedon Nov 3, 2025
Not a Google employee, but refer to my earlier comment, there is no way to support
onPopInvokedfor the iOS back gesture. The request is internally inconsistent.onPopInvokedshould document this limitation, but it is working as intended. Google will not be able to solve this for you as the request is inherently not possible (at least not without coherent UX).#138624 (comment)