Skip to content

Conversation

LukasMirbt
Copy link
Contributor

Adds PopScope which prevents iOS back gesture from popping ShellRoute when there are active sub-routes.

Closes flutter/flutter#120353.

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 3

Copy link

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

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 fixes an issue with the iOS back gesture on ShellRoute and StatefulShellRoute. The fix involves wrapping the nested navigator in a PopScope to prevent it from being popped when there are active sub-routes. The logic seems correct and is well-covered by new regression tests for both ShellRoute and StatefulShellRoute.

I have a couple of suggestions for the new test files to improve code clarity and maintainability. Please see my comments.

@LukasMirbt LukasMirbt force-pushed the go-router/shell-route-ios-back-gesture branch 3 times, most recently from 986413c to 1a2594d Compare September 7, 2025 19:42
errorBuilder: widget.errorBuilder,
errorPageBuilder: widget.errorPageBuilder,
requestFocus: widget.requestFocus,
return PopScope(
Copy link
Contributor

Choose a reason for hiding this comment

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

@justinmc is this the right way to prevent an iOS backgesture? or should we use NavigatorPopHandler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like Justin is on vacation. Is there anybody else we can loop in or should we wait for him?

Screenshot 2025-09-09 at 19 38 54

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's wait for him. I "think" we should use NavigatorPopHandler and I also remember Justin was also fixing something about the nested navigator in go_router

Copy link
Contributor

Choose a reason for hiding this comment

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

@LukasMirbt Could you check if flutter/flutter#152330 fixes this issue? If so I'd prefer to wait for that PR. If not, we should confirm that any fix made inside of go_router here will still work after that PR lands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@justinmc flutter/flutter#152330 does seem to fix this issue 🎉

However, I don't see a compelling reason to wait for your PR since it will most likely take a couple of months before it hits stable, even once it's merged, and the issue linked in this PR has over 50 upvotes.

All the go_router tests + regression tests seem to pass (on your fork) both with and without the fix added in this PR. I propose we add a TODO to remove the PopScope once your fix has hit stable and merge this PR in the meantime.

Let me know if you disagree!

Copy link
Contributor

Choose a reason for hiding this comment

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

Can the change here and flutter change coexist? If so, can you add a test to make sure android back button work correctly so that when stable roll into package won't break go_router?

Otherwise, adding a todo and merge this now sgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can the change here and flutter change coexist?

Yes, it seems like the fix is forward compatible 👍 The tests are passing with flutter/flutter#152330.

If so, can you add a test to make sure android back button work correctly so that when stable roll into package won't break go_router?

Done ✅

Otherwise, adding a todo and merge this now sgtm

TODO added as well!

@chunhtai chunhtai requested a review from justinmc September 8, 2025 18:50
@wengxianxun

This comment was marked as abuse.

@LukasMirbt LukasMirbt force-pushed the go-router/shell-route-ios-back-gesture branch 2 times, most recently from 2583e75 to 18b96f1 Compare September 19, 2025 19:40
@LukasMirbt LukasMirbt force-pushed the go-router/shell-route-ios-back-gesture branch from 867f618 to c3c3f87 Compare September 19, 2025 19:41
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[go_router] ShellRoutes break iOS swipe back navigation
4 participants