[go_router] Fix predictive back popping inactive StatefulShellBranch routes#11910
[go_router] Fix predictive back popping inactive StatefulShellBranch routes#11910danyalahmed1995 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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.
|
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. |
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
StatefulShellBranchnavigators.Issues fixed
Fixes flutter/flutter#188018
Tests
Ran from
packages/go_router: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_routerpackage behavior. If the repository tooling or reviewer requires a package version andCHANGELOG.mdupdate for this fix, I will add it before marking the PR ready/mergeable.Pre-Review Checklist
[shared_preferences]///).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-assistbot 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
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