Skip to content

[go_router] Fix predictive back popping inactive StatefulShellBranch routes#11910

Draft
danyalahmed1995 wants to merge 2 commits into
flutter:mainfrom
danyalahmed1995:repro/go-router-predictive-back-188018
Draft

[go_router] Fix predictive back popping inactive StatefulShellBranch routes#11910
danyalahmed1995 wants to merge 2 commits into
flutter:mainfrom
danyalahmed1995:repro/go-router-predictive-back-188018

Conversation

@danyalahmed1995

@danyalahmed1995 danyalahmed1995 commented Jun 15, 2026

Copy link
Copy Markdown

PR title

[go_router] Fix predictive back popping inactive StatefulShellBranch routes

PR body

Fixes flutter/flutter#188018

Description

This fixes Android system/predictive back handling for StatefulShellRoute.indexedStack.

Previously, when branch B was active, Android system/predictive back could still pop routes from inactive branch navigators. For example, inactive branch A and C routes could be popped while the active location remained /B1.

This change tracks whether a stateful shell branch navigator is active and prevents inactive branch navigators from participating in system/predictive back handling.

A regression test was added to verify that system/predictive back on the active branch does not pop inactive StatefulShellBranch navigators.

Issues fixed

Fixes flutter/flutter#188018

Tests

Ran from packages/go_router:

flutter test test/stateful_shell_route_system_back_test.dart
flutter test test/shell_route_system_back_test.dart
flutter test test/delegate_test.dart
flutter test test/go_router_test.dart
flutter analyze
git diff --check

Notes

No before/after screenshots are included because this is a navigation state/Android system-back behavior fix covered by a regression test.

No public API documentation update is needed because this does not add or change a public API. The behavior is covered by the added regression test.

Version/CHANGELOG note: this PR changes go_router package behavior. If the repository tooling or reviewer requires a package version and CHANGELOG.md update for this fix, I will add it before marking the PR ready/mergeable.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mechanism to prevent inactive StatefulShellRoute branches from being popped by the system back gesture. It adds a navigatorActive ValueListenable to the navigator builder, which is updated based on the active branch index in StatefulNavigationShellState. A new _BranchNavigatorPopScope widget wraps the branch page child with a PopScope whose canPop state is driven by this listenable. Additionally, a test is added to verify that inactive branches are not popped during back gestures. No review comments were provided.

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Thanks for the contribution!

In the future, please do not delete the checklist that is in the PR template; it is there for a reason. This PR is missing required elements described in the checklist, which need to be addressed before it moves forward with review.

I am marking the PR as a Draft. Please re-add and complete the checklist, updating the PR as appropriate, and when that’s complete please feel free to mark the PR as ready for review.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft June 16, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: go_router triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go_router] Android predictive back pops one screen from each StatefulShellBranch and popped screens dispose called in the wrong order

2 participants