Skip to content

[go_router] Add GoRouterState state parameter to GoRouterData.onExit - #6495

Merged
auto-submit[bot] merged 9 commits into
flutter:mainfrom
ValentinVignal:go-router/add-state-to-on-exit
Apr 24, 2024
Merged

[go_router] Add GoRouterState state parameter to GoRouterData.onExit#6495
auto-submit[bot] merged 9 commits into
flutter:mainfrom
ValentinVignal:go-router/add-state-to-on-exit

Conversation

@ValentinVignal

Copy link
Copy Markdown
Contributor

Part of flutter/flutter#137394

I need to add the state parameter to the onExit method so I can use the factoryImpl(state):

Widgetbuilder(BuildContext context, GoRouterState state) =>
factoryImpl(state).build(context, state);
Page<void> pageBuilder(BuildContext context, GoRouterState state) =>
factoryImpl(state).buildPage(context, state);
FutureOr<String?> redirect(BuildContext context, GoRouterState state) =>
factoryImpl(state).redirect(context, state);
returnGoRoute(
path: path,
name: name,
builder: builder,
pageBuilder: pageBuilder,
redirect: redirect,
routes: routes,
parentNavigatorKey: parentNavigatorKey,
);
}

Pre-launch Checklist

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

@chunhtaichunhtai 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 LGTM, but we should have a bit more test.

Since this is a breaking change can you write a breaking change doc?

You can also explore dart fix, I think you can add a new rule there to auto migrate customers' code.

builder: (BuildContext context, GoRouterState state) =>
DummyScreen(key: page1),
onExit: (BuildContext context) {
onExit: (BuildContext context, GoRouterState state) {

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.

Can you add a new test that assert the properties in state, to make sure the state is accurate with the route?

@chunhtai

Copy link
Copy Markdown
Contributor

See https://github.com/flutter/packages/blob/main/packages/go_router/lib/fix_data.yaml

if you can write a rule that cover all cases, the migration doc can be as simple as please run dart fix --apply

…-to-on-exit
# Conflicts:
#	packages/go_router/CHANGELOG.md
#	packages/go_router/pubspec.yaml
@ValentinVignal

Copy link
Copy Markdown
ContributorAuthor

Since this is a breaking change can you write a breaking change doc?

Okay sure I'll write one ! 👍

@ValentinVignal

Copy link
Copy Markdown
ContributorAuthor

@chunhtai I'm struggling a bit with the dart fix. Is there a way to add a parameter to a method given to a field of a class constructor ? I didn't find it in the doc

(I also posted a message on discord https://discord.com/channels/608014603317936148/608021635370582020/1228715527073955912)

@chunhtai

Copy link
Copy Markdown
Contributor

@chunhtai

Copy link
Copy Markdown
Contributor

you can also check the syntax here https://github.com/flutter/flutter/wiki/Data-driven-Fixes

@ValentinVignal

ValentinVignal commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor

See https://github.com/flutter/packages/blob/main/packages/go_router/lib/fix_data.yaml

if you can write a rule that cover all cases, the migration doc can be as simple as please run dart fix --apply

That's a bit different, it looks like the addParameter is used to change occurrences of:

MyClass.myMethod(param1);

into

MyClass.myMethod(param1, param2);

while I need to add a parameter to a method given as a argument:

GoRouter(
onExit: (BuildContext context) =>true;
);

into

GoRouter(
onExit: (BuildContext context, GoRouterState state) =>true;
);

@ValentinVignal
ValentinVignalforce-pushed the go-router/add-state-to-on-exit branch from 46248ba to 3b3c61cCompareApril 16, 2024 07:50
sfshaza2 pushed a commit to flutter/website that referenced this pull request Apr 17, 2024
Adds the migration guide for go router v14
(flutter/packages#6495)
Fixesflutter/flutter#146805
## Presubmit checklist
- [x] This PR doesn’t contain automatically generated corrections
(Grammarly or similar).
- [x] This PR follows the [Google Developer Documentation Style
Guidelines](https://developers.google.com/style) — for example, it
doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person).
- [x] This PR uses [semantic line
breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks)
of 80 characters or fewer.
Co-authored-by: Brett Morgan <brettmorgan@google.com>
@ValentinVignal

Copy link
Copy Markdown
ContributorAuthor

The migration doc flutter/website#10423 got merged

@chunhtaichunhtai 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, thanks for improving the API!

@hannah-hyjhannah-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

@chunhtaichunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 24, 2024
@auto-submit
auto-submitBot merged commit 26f660b into flutter:mainApr 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 25, 2024
auto-submitBot pushed a commit to flutter/flutter that referenced this pull request Apr 25, 2024
flutter/packages@cf6d280...fde908d
2024-04-25 49699333+dependabot[bot]@users.noreply.github.com Bump actions/checkout from 4.1.3 to 4.1.4 (flutter/packages#6609)
2024-04-24 32538273+ValentinVignal@users.noreply.github.com [go_router] Add `GoRouterState state` parameter to `GoRouterData.onExit` (flutter/packages#6495)
2024-04-24 15619084+vashworth@users.noreply.github.com Add CI steps to test iOS and macOS plugins with both CocoaPods and Swift Package Manager (flutter/packages#6557)
2024-04-24 engine-flutter-autoroll@skia.org Roll Flutter from 77043ba to dba4f77 (30 revisions) (flutter/packages#6607)
2024-04-24 stuartmorgan@google.com [camera] Finish converting iOS to Pigeon (flutter/packages#6601)
2024-04-24 47866232+chunhtai@users.noreply.github.com [go_router] Fixes an issue where route future does not complete when � (flutter/packages#6596)
2024-04-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Bump legacy all_packages project AGP version to 7.0.0, Gradle version to 7.0.2 (#6591)" (flutter/packages#6605)
2024-04-23 reidbaker@google.com [in_app_purchase_android] Readme update for Alternative billing (flutter/packages#6578)
2024-04-23 43054281+camsim99@users.noreply.github.com Bump legacy all_packages project AGP version to 7.0.0, Gradle version to 7.0.2 (flutter/packages#6591)
2024-04-23 engine-flutter-autoroll@skia.org Roll Flutter from 140edb9 to 77043ba (21 revisions) (flutter/packages#6599)
2024-04-23 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.1 to 3.25.2 (flutter/packages#6597)
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,rmistry@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
auto-submitBot pushed a commit that referenced this pull request May 16, 2024
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this pull request May 22, 2024
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this pull request May 22, 2024
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
bisor0627 pushed a commit to bisor0627/packages that referenced this pull request Jun 19, 2026
bisor0627 pushed a commit to bisor0627/packages that referenced this pull request Jun 19, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmitMerge PR when tree becomes green via auto submit Appp: go_router

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@ValentinVignal@chunhtai@hannah-hyj