Skip to content

Fixes navigator may not report correct canhandlepop when propagate in…#186705

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
chunhtai:issues/181945
Jun 24, 2026
Merged

Fixes navigator may not report correct canhandlepop when propagate in…#186705
auto-submit[bot] merged 4 commits into
flutter:masterfrom
chunhtai:issues/181945

Conversation

@chunhtai

@chunhtai chunhtai commented May 18, 2026

Copy link
Copy Markdown
Contributor

…ner navigation notification

When propagate the notifcation from the inner nested navigator, it didn't take the PopScope in between the two navigator into account.

if the widget tree looks like this

Navigator1
   PopScope(canpop: false)
       Navigator2

when the navigator 2 report canHandlePop = false, the Navigator1 receives it but it just check against its NavigatorState.canPop, which doesn't take the PopScope in between into account.

This pr changes the logic that it now also check the modalroute's popdisposition

fixes #181945

Pre-launch Checklist

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

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

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.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 18, 2026
@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: routes Navigator, Router, and related APIs. labels May 18, 2026

@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 refactors NavigatorState to centralize pop-handling logic within a new _getNavigatorCanHandlePop method and adds a test case for nested navigators using PopScope. The review feedback suggests simplifying the logic in _getNavigatorCanHandlePop to improve efficiency and adding documentation to the private method to align with the repository's style guide.

Comment thread packages/flutter/lib/src/widgets/navigator.dart
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[Text('Home/PopScope Page')],
),
testWidgets('pop scope can have Object? generic type while route has stricter generic type', (

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

these are format change

@github-actions github-actions Bot removed the CICD Run CI/CD label May 19, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 19, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 19, 2026
@chunhtai chunhtai added the CICD Run CI/CD label May 19, 2026
@chunhtai
chunhtai requested a review from justinmc May 19, 2026 21:30

@justinmc justinmc 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.

Thanks for fixing! Indeed that's an oversight of PopScope in between Navigators.

Comment on lines -5936 to +5934
if (notification.canHandlePop || !canPop()) {
if (notification.canHandlePop || !_getNavigatorCanHandlePop()) {

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.

Good catch!

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2026
@auto-submit

auto-submit Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/186705, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 24, 2026
@chunhtai chunhtai added the CICD Run CI/CD label Jun 24, 2026
@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 24, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jun 24, 2026
Merged via the queue into flutter:master with commit a658b9e Jun 24, 2026
95 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 24, 2026
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
flutter#186705)

…ner navigation notification

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

When propagate the notifcation from the inner nested navigator, it
didn't take the PopScope in between the two navigator into account.

if the widget tree looks like this
```
Navigator1
   PopScope(canpop: false)
       Navigator2
```
when the navigator 2 report canHandlePop = false, the Navigator1
receives it but it just check against its NavigatorState.canPop, which
doesn't take the PopScope in between into account.

This pr changes the logic that it now also check the modalroute's
popdisposition

fixes flutter#181945

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

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

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
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.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Back button closes app instead of navigating to first tab in go_router 17.1.0 with ShellRoute

4 participants