flutter / flutter/flutter

onDidRemovePage is called when deleting a page below.

Open
#160,463 7 comments 6 reactions 0 assignees View on GitHub
f: routes found in release: 3.27 found in release: 3.28 framework has reproducible steps P3 team-framework triaged-framework
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Steps to reproduce

1. Clone the [RubigoNavigator](https://github.com/jsroest/rubigo_navigator) repository.
2. Start the example app.
3. Navigate from S100 to S200 by pressing the button with label "Push S200".
4. Navigate from S200 to S300 by pressing the button with label "Push S300".
5. Note the following lines in the debug console:

```
flutter: Screen stack: s100
flutter: push(s200) called
flutter: Screen stack: s100 => s200
flutter: push(s300) called
flutter: Screen stack: s100 => s200 => s300
```

1. Delete S200 from the screen stack by pressing the button with label "Remove S200"
2. Note the following lines in the debug console:

```
flutter: remove(s200) called
flutter: Screen stack: s100 => s300
flutter: onDidRemovePage(s300) called by Flutter framework
flutter: and redirected to pop().
flutter: pop() called
flutter: Screen stack: s100
flutter: onDidRemovePage(s300) called by Flutter framework
flutter: but ignored by us.
```

### Expected results

onDidRemovePage should only be called when the top most page is removed by the Flutter Framework, for example when the stack changes because the user presses or uses:

1. Android BackButton
2. Android predictive back gesture
3. iOS swipe back gesture
4. .....?

onDidRemovePage should not be called when our code removes pages. Why should we be informed, when we remove the page ourselves in code?

### Actual results

It looks like that every page that is not in the new set of pages is reported back to the router delegate by calling onDidRemovePage. You might also want to try to navigate from S300 directly to S100 by pressing "PopTo S100".

This will be in the console output.
```
flutter: Screen stack: s100 => s200 => s300
flutter: popTo(s100) called
flutter: Screen stack: s100
flutter: onDidRemovePage(s300) called by Flutter framework
flutter: but ignored by us.
flutter: onDidRemovePage(s200) called by Flutter framework
flutter: but ignored by us.
```

### Code sample

See steps to reproduce, for a complete sample.

### Screenshots or Video

Screenshots / Video demonstration

https://github.com/user-attachments/assets/46d00704-83c6-4030-8d93-8ad0d9bf9167

### Logs

Logs

```console
Syncing files to device macOS...
flutter: Screen stack: s100
flutter: push(s200) called
flutter: push(s200) called
flutter: Screen stack: s100 => s200 => s200
flutter: push(s300) called
flutter: Screen stack: s100 => s200 => s200 => s300
flutter: remove(s200) called
flutter: Screen stack: s100 => s200 => s300
flutter: onDidRemovePage(s300) called by Flutter framework
flutter: and redirected to pop().
flutter: pop() called
flutter: Screen stack: s100 => s200
flutter: onDidRemovePage(s300) called by Flutter framework
flutter: but ignored by us.
```

### Flutter Doctor output

Doctor output

```console
➜ rubigo_navigator git:(main) fvm flutter doctor -v
[✓] Flutter (Channel stable, 3.27.1, on macOS 15.1.1 24B91 darwin-x64, locale en-NL)
• Flutter version 3.27.1 on channel stable at /Users/johannesroest/fvm/versions/3.27.1
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 17025dd882 (26 hours ago), 2024-12-17 03:23:09 +0900
• Engine revision cb4b5fff73
• Dart version 3.6.0
• DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/johannesroest/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16C5032a
• CocoaPods version 1.16.2

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

[✓] Android Studio (version 2024.1)
• 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.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.95.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
• iPhone van Sander (mobile) • 00008120-001635020E43A01E • ios • iOS 18.1.1 22B91
• macOS (desktop) • macos • darwin-x64 • macOS 15.1.1 24B91 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.140

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

• No issues found!
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.