Skip to content

Conversation

@ValentinVignal
Copy link
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. 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 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.

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.

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
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
Contributor Author

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.

@ValentinVignal
Copy link
Contributor Author

ValentinVignal commented Jan 15, 2026

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 :
String Function(T) encode;
T Function(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?

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

Labels

p: go_router_builder triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants