Skip to content

[go_router] Allow users to specify onExit as optional#11150

Merged
auto-submit[bot] merged 13 commits into
flutter:mainfrom
hantrungkien:go-router/support-on-exit-optional
May 26, 2026
Merged

[go_router] Allow users to specify onExit as optional#11150
auto-submit[bot] merged 13 commits into
flutter:mainfrom
hantrungkien:go-router/support-on-exit-optional

Conversation

@hantrungkien

Copy link
Copy Markdown
Contributor

Related to flutter/flutter#183099

Allow users to specify onExit as optional

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

@hantrungkien hantrungkien requested a review from chunhtai as a code owner March 2, 2026 03:42
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added p: go_router triage-framework Should be looked at in framework triage labels Mar 2, 2026
@google-cla

google-cla Bot commented Mar 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 an overrideOnExit parameter to TypedGoRoute and TypedRelativeGoRoute. This parameter controls whether the onExit method on the corresponding route data class is invoked. The default is false, which changes the previous behavior where onExit was always called. My review identifies this as a breaking change that should be handled according to semantic versioning. I've also noted the lack of tests for the new functionality and suggested improvements to the naming and documentation for clarity.

Comment thread packages/go_router/lib/src/route_data.dart
Comment thread packages/go_router/pubspec.yaml Outdated
Comment thread packages/go_router/lib/src/route_data.dart Outdated
@hantrungkien

Copy link
Copy Markdown
Contributor Author

go_router_builder PR: #11151

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! You’ve checked boxes in the PR checklist above that are not reflected in this PR, so I’m assuming this is a work in progress and am marking it as a Draft. Please review the checklist, updating the PR as appropriate, and when the state of the PR as posted reflects the checklist please feel free to mark it as ready for review.

  • I added new tests to check the change I am making, or I have commented below to indicate which test exemption this PR falls under1.
  • All existing and new tests are passing.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft March 2, 2026 14:23
@hantrungkien

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g Thank you for your quick response. I’ve added the missing items. Please take a look and review them for me!

@hantrungkien hantrungkien marked this pull request as ready for review March 2, 2026 16:01

@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 the overrideOnExit parameter to TypedGoRoute and TypedRelativeGoRoute, allowing users to explicitly control whether the onExit method of route data classes is invoked. The onExit callback in _GoRouteParameters has been made optional to support this. The changes include updates to the CHANGELOG.md and pubspec.yaml files, along with comprehensive test cases for the new functionality. The implementation is clear, well-documented, and correctly tested, adhering to the repository's coding standards.

required T Function(GoRouterState) factory,
GlobalKey<NavigatorState>? parentNavigatorKey,
List<RouteBase> routes = const <RouteBase>[],
bool hasOverriddenOnExit = false,

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.

This may be a breaking change for older version of go router builder because this will always be false and onExit will break. will need to come up with a different way or a migration guide

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.

@chunhtai I have updated hasOverriddenOnExit to have a default value of null for backward compatibility with older versions of go_router_builder. Please review it for me!

@chunhtai

Copy link
Copy Markdown
Contributor

also ci is red

@hantrungkien

Copy link
Copy Markdown
Contributor Author

also ci is red

@chunhtai I ran all tests for go_router and go_router_builder locally (including the example), and they all passed. Could a maintainer please take a look or trigger a re-run?

@Piinks Piinks added the CICD Run CI/CD label Mar 17, 2026
@hantrungkien

Copy link
Copy Markdown
Contributor Author

@chunhtai I've updated pending_changelogs. Could a maintainer please take a look or trigger a re-run?

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

LGTM besides the new line at the end

@@ -0,0 +1,3 @@
changelog: |
- Adds `hasOverriddenOnExit` parameter to `GoRouteData.$route` and `RelativeGoRouteData.$route` helper methods for type-safe routes. When set to `true`, enables custom `onExit` callback invocation from route data classes extending `GoRouteData` or `RelativeGoRouteData` when the route is removed from the navigation stack.
version: minor

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.

a new line at the end

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.

@chunhtai Actually, my file only has 3 lines. It seems like the issue happens because the changelog values are long, so it ends up like this—similar to this file.

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.

@chunhtai I checked again in the browser on an extended screen that is larger than the MacBook’s screen, and everything looks fine.

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.

@chunhtai Hi, is there anything else needed from your side for this PR?

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.

a new line at the end of line 3, this is better for source control

@chunhtai chunhtai requested a review from hannah-hyj April 6, 2026 19:55
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 8, 2026
@stuartmorgan-g stuartmorgan-g requested a review from chunhtai May 5, 2026 18:25

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

LGTM, left a comment and waiting for @hannah-hyj for secondary review who is OOO

@@ -0,0 +1,3 @@
changelog: |
- Adds `hasOverriddenOnExit` parameter to `GoRouteData.$route` and `RelativeGoRouteData.$route` helper methods for type-safe routes. When set to `true`, enables custom `onExit` callback invocation from route data classes extending `GoRouteData` or `RelativeGoRouteData` when the route is removed from the navigation stack.
version: minor

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.

a new line at the end of line 3, this is better for source control

@hannah-hyj hannah-hyj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

_GoRouteParameters _createGoRouteParameters<T extends _GoRouteDataBase>({
required T Function(GoRouterState) factory,
required Expando<_GoRouteDataBase> expando,
bool? hasOverriddenOnExit,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe add a comment about that when hasOverriddenOnExit is null it's handled the same as true for backward compatibility?

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.

@hannah-hyj I've added. Please help me review.

@Piinks Piinks added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels May 26, 2026
@auto-submit auto-submit Bot merged commit db270b4 into flutter:main May 26, 2026
82 checks passed
AngeloAvv pushed a commit to AngeloAvv/flutter that referenced this pull request May 27, 2026
…r#187174)

flutter/packages@fc795e5...4b424d7

2026-05-27 engine-flutter-autoroll@skia.org Roll Flutter from
f3a4b98 to c8f2f16 (29 revisions) (flutter/packages#11795)
2026-05-27 stuartmorgan@google.com [google_maps_flutter] Remove
duplicated privacy manifest entries (flutter/packages#11791)
2026-05-27 stuartmorgan@google.com [tool] Add config options needed by
core-packages (flutter/packages#11784)
2026-05-26 kienhantrung@gmail.com [go_router] Allow users to specify
onExit as optional (flutter/packages#11150)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
Related to flutter/flutter#183099

Allow users to specify onExit as optional

## Pre-Review Checklist

**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.

[^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.
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
…r#187174)

flutter/packages@fc795e5...4b424d7

2026-05-27 engine-flutter-autoroll@skia.org Roll Flutter from
f3a4b98 to c8f2f16 (29 revisions) (flutter/packages#11795)
2026-05-27 stuartmorgan@google.com [google_maps_flutter] Remove
duplicated privacy manifest entries (flutter/packages#11791)
2026-05-27 stuartmorgan@google.com [tool] Add config options needed by
core-packages (flutter/packages#11784)
2026-05-26 kienhantrung@gmail.com [go_router] Allow users to specify
onExit as optional (flutter/packages#11150)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD 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.

5 participants