Repository: flutter
Issue: PopScope seems to be incompatible with GoRouter
Labels: customer: crowd,package,has reproducible steps,P1,p: go_router,:+1:,team-go_router,:hourglass_flowing_sand:,found in release: 3.16,found in release: 3.17

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

Original comment was made at https://github.com/flutter/flutter/issues/138525#issuecomment-1815292384 but I'm pasting here:

[...] our team was investigating `PopScope` and found some interesting behavior that can be reproduced using [this repo](https://github.com/btrautmann/pop_scope_repro). 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](https://github.com/btrautmann/pop_scope_repro).

### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] 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!
```

</details>