Skip to content

[go_router_builder] Add support for @TypedGoRouteParameter to customize parameter names - #10793

Merged
auto-submit[bot] merged 11 commits into
flutter:mainfrom
ValentinVignal:go-router-builder/Support-custom-parameter-names
Feb 4, 2026
Merged

[go_router_builder] Add support for @TypedGoRouteParameter to customize parameter names#10793
auto-submit[bot] merged 11 commits into
flutter:mainfrom
ValentinVignal:go-router-builder/Support-custom-parameter-names

Conversation

@ValentinVignal

Copy link
Copy Markdown
Contributor

Relates to flutter/flutter#112152

Add support for @TypedGoRouteParameter to customize parameter names

Needs #10792 to get merged first

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

@gemini-code-assistgemini-code-assistBot 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 support for the @TypedGoRouteParameter annotation, allowing developers to customize the names of URL parameters in typed routes. The core change is a new uriName extension getter on FormalParameterElement which reads the custom name from the annotation or defaults to the kebab-case version of the field name. The code generator has been updated to use this new getter when constructing query parameters. The changes are well-tested with a new example and test cases. My feedback includes a suggestion to improve the readability of the code that extracts the annotation value.

Comment threadpackages/go_router_builder/lib/src/type_helpers.dart Outdated

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

Looking at the issue, is there a plan for custom converter?

@TypedGoRoute<IntRoute>(path: '/int-route')
class IntRoute extends GoRouteData with $IntRoute {
IntRoute({
@TypedGoRouteParameter(name: 'intField') this.intField,

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.

should this be on the property declaration?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It was easier to put it in the parameter. But if you prefer, we can move it to the property instead. It will require a bit more code, though.

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.

I think leave it here is fine, thinking about it more we may have inline declaration for constructor in the future dart language feature dart-lang/language#2364
so we not necessary have a standalone property declaration

@ValentinVignal

ValentinVignal commented Jan 15, 2026

Copy link
Copy Markdown
ContributorAuthor

Looking at the issue, is there a plan for custom converter?

Yes, thank you for asking. It made me realise I forgot to put a comment on the PR.

  1. Ultimately, this annotation could have 2 more methods :
StringFunction(T) encode;
TFunction(String) decode;

but that will be for another PR. (Or it could be another annotation?)

  1. We can introduce (in a future PR) a similar annotation for enum entries. Ex:
eum MyEnum {
@GoRouterEnumEntry(name:'customName1')
entry1,
@GoRouterEnumEntry(name:'custom_name_2')
entry2,
}

I'm not too proud of the name TypedGoRouteParameter, maybe you'd have a better name in mind?

@chunhtai

chunhtai commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

I'm not too proud of the name TypedGoRouteParameter, maybe you'd have a better name in mind?

Maybe just call TypedQueryParameter? we don't have to stick the trademark on every class .

@chunhtai

Copy link
Copy Markdown
Contributor

(also please use re-request review if you want me to take a look at the PR again)

@ValentinVignal
ValentinVignalforce-pushed the go-router-builder/Support-custom-parameter-names branch 2 times, most recently from ad8d816 to 533cd6cCompareJanuary 25, 2026 08:58
@ValentinVignal

Copy link
Copy Markdown
ContributorAuthor

Noted, I updated the name of the decorator to TypedQueryParameter

@TypedGoRoute<IntRoute>(path: '/int-route')
class IntRoute extends GoRouteData with $IntRoute {
IntRoute({
@TypedQueryParameter(name: 'intField') this.intField,

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.

I like this. it make it a lot more readable.

I kinda wish we could have annotate each query parameter with this instead of relying on position parameter and named parameter. but I think that ship may have sailed for too long


// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';

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.

we should add a test for this example to ensure it compiles

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Makes sense, I added more tests in Update tests

_typedQueryParameterChecker.firstAnnotationOf(this),
);
final String name =
typedQueryParameterReader.peek('name')?.stringValue ??

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.

When developer sets the name, are they expected to encode the string themself? we definitely need to document it here https://github.com/flutter/packages/pull/10792/files#diff-7d10b245947af9f5b39c2a5b1a064ac581386eb3efd95d1dae540a687afd4255R646

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure I understand the question. What so you mean by "encode the string themselve"?

@chunhtaichunhtaiJan 26, 2026

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.

if they want to use space in the name for some reason, should they provide name: 'q a', or name: 'q%20a'

@ValentinVignalValentinVignalJan 27, 2026

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Oh okay understood! They don't need to encode it themselves. Uri` does it for us.

In the end, it passes the name to uri:

final uri =Uri(
queryParameters: {
'withNoSpace': ['1'],
'with space': ['2'],
},
);
print(uri)

The example above yields

?withNoSpace=1&with+space=2

If the user names it q a, it will be transformed to q+a in the URL. Is this acceptable for you?

For example, I've updated the example (I'll push it soon) to be

@TypedGoRoute<IntRoute>(path:'/int-route')
classIntRouteextendsGoRouteDatawith$IntRoute {
IntRoute({
@TypedQueryParameter(name:'intField') this.intField,
@TypedQueryParameter(name:'int_field_with_default_value')
this.intFieldWithDefaultValue =1,
@TypedQueryParameter(name:'int field') this.intFieldWithSpace,
});

and here is what it looks like:

Screenshot 2026-01-27 at 4 55 51 PM

The url is /int-route?intField=1&int_field_with_default_value=2&int+field=2

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I updated the changelogs here Update documentation, let me know if that's acceptable for you or not

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.

updating the change log is good, but we should make sure the documentation also mentioned it.
i.e. here https://github.com/flutter/packages/pull/10792/files#diff-7d10b245947af9f5b39c2a5b1a064ac581386eb3efd95d1dae540a687afd4255R646

@ValentinVignal
ValentinVignalforce-pushed the go-router-builder/Support-custom-parameter-names branch from 533cd6c to 69bce95CompareJanuary 27, 2026 08:43

@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

Comment threadpackages/go_router_builder/CHANGELOG.md Outdated

@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

@ValentinVignal
ValentinVignalforce-pushed the go-router-builder/Support-custom-parameter-names branch from 64a2b45 to 268887cCompareFebruary 3, 2026 09:01
@ValentinVignalValentinVignal added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 4, 2026
@auto-submit
auto-submitBot merged commit df85ef0 into flutter:mainFeb 4, 2026
81 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 4, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 4, 2026
github-merge-queueBot pushed a commit to flutter/flutter that referenced this pull request Feb 4, 2026
flutter/packages@5b1bea8...3bddf2c
2026-02-04 ivan-vanyusho@yandex-team.ru [camera_avfoundation] ios saving
path (flutter/packages#10832)
2026-02-04 stuartmorgan@google.com [video_player] Remove OCMock
(flutter/packages#10932)
2026-02-04 stuartmorgan@google.com [google_maps_flutter] Remove use of
OCMock (flutter/packages#10863)
2026-02-04 32538273+ValentinVignal@users.noreply.github.com
[go_router_builder] Add support for `@TypedGoRouteParameter` to
customize parameter names (flutter/packages#10793)
2026-02-03 engine-flutter-autoroll@skia.org Roll Flutter from
c305f1f to bf701fe (9 revisions) (flutter/packages#10957)
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
LongCatIsLooong pushed a commit to LongCatIsLooong/flutter that referenced this pull request Feb 6, 2026
…r#181918)
flutter/packages@5b1bea8...3bddf2c
2026-02-04 ivan-vanyusho@yandex-team.ru [camera_avfoundation] ios saving
path (flutter/packages#10832)
2026-02-04 stuartmorgan@google.com [video_player] Remove OCMock
(flutter/packages#10932)
2026-02-04 stuartmorgan@google.com [google_maps_flutter] Remove use of
OCMock (flutter/packages#10863)
2026-02-04 32538273+ValentinVignal@users.noreply.github.com
[go_router_builder] Add support for `@TypedGoRouteParameter` to
customize parameter names (flutter/packages#10793)
2026-02-03 engine-flutter-autoroll@skia.org Roll Flutter from
c305f1f to bf701fe (9 revisions) (flutter/packages#10957)
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
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
…r#181918)
flutter/packages@5b1bea8...3bddf2c
2026-02-04 ivan-vanyusho@yandex-team.ru [camera_avfoundation] ios saving
path (flutter/packages#10832)
2026-02-04 stuartmorgan@google.com [video_player] Remove OCMock
(flutter/packages#10932)
2026-02-04 stuartmorgan@google.com [google_maps_flutter] Remove use of
OCMock (flutter/packages#10863)
2026-02-04 32538273+ValentinVignal@users.noreply.github.com
[go_router_builder] Add support for `@TypedGoRouteParameter` to
customize parameter names (flutter/packages#10793)
2026-02-03 engine-flutter-autoroll@skia.org Roll Flutter from
c305f1f to bf701fe (9 revisions) (flutter/packages#10957)
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
rickhohler pushed a commit to rickhohler/flutter that referenced this pull request Feb 19, 2026
…r#181918)
flutter/packages@5b1bea8...3bddf2c
2026-02-04 ivan-vanyusho@yandex-team.ru [camera_avfoundation] ios saving
path (flutter/packages#10832)
2026-02-04 stuartmorgan@google.com [video_player] Remove OCMock
(flutter/packages#10932)
2026-02-04 stuartmorgan@google.com [google_maps_flutter] Remove use of
OCMock (flutter/packages#10863)
2026-02-04 32538273+ValentinVignal@users.noreply.github.com
[go_router_builder] Add support for `@TypedGoRouteParameter` to
customize parameter names (flutter/packages#10793)
2026-02-03 engine-flutter-autoroll@skia.org Roll Flutter from
c305f1f to bf701fe (9 revisions) (flutter/packages#10957)
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
…mize parameter names (flutter#10793)
Relates to flutter/flutter#112152
Add support for `@TypedGoRouteParameter` to customize parameter names
Needs flutter#10792 to get merged first
## 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.
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_buildertriage-frameworkShould be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@ValentinVignal@chunhtai@hannah-hyj