-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router_builder] Add support for @TypedGoRouteParameter to customize parameter names
#10793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[go_router_builder] Add support for @TypedGoRouteParameter to customize parameter names
#10793
Conversation
There was a problem hiding this 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.
chunhtai
left a comment
There was a problem hiding this 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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Yes, thank you for asking. It made me realise I forgot to put a comment on the PR.
String Function(T) encode;
T Function(String) decode;but that will be for another PR. (Or it could be another annotation?)
eum MyEnum {
@GoRouterEnumEntry(name: 'customName1')
entry1,
@GoRouterEnumEntry(name: 'custom_name_2')
entry2,
}I'm not too proud of the name |
Relates to flutter/flutter#112152
Add support for
@TypedGoRouteParameterto customize parameter namesNeeds #10792 to get merged first
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).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-assistbot 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
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