[go_router] Add encoder,decoder and compare parameters to TypedQueryParameter#11067
[go_router] Add encoder,decoder and compare parameters to TypedQueryParameter#11067ValentinVignal wants to merge 4 commits intoflutter:mainfrom
encoder,decoder and compare parameters to TypedQueryParameter#11067Conversation
encoder,decoder and compare parameters to `TypedQueryParameterencoder,decoder and compare parameters to TypedQueryParameter
There was a problem hiding this comment.
Code Review
This pull request enhances TypedQueryParameter by adding encoder, decoder, and compare parameters, allowing for more flexible handling of query parameters in type-safe routes. The changes are well-implemented and include corresponding updates to the changelog, pubspec, and tests. I have one suggestion to improve the clarity of the documentation for the new compare parameter to prevent potential misuse.
| /// A function that compares two parameter values for equality. | ||
| /// | ||
| /// Returns `true` if the values are different and `false` if they are the | ||
| /// same. This is used to determine whether a parameter should be included in | ||
| /// the URI when it has a default value. |
There was a problem hiding this comment.
The documentation for the compare function is a bit confusing. The first sentence says it's for equality comparison, but the following sentence states it returns true if the values are different. This is counter-intuitive for a function that is described as comparing for equality.
To avoid confusion for developers using this API, I suggest rephrasing the documentation to be more direct about its purpose. For example, you could describe it as an inequality check.
| /// A function that compares two parameter values for equality. | |
| /// | |
| /// Returns `true` if the values are different and `false` if they are the | |
| /// same. This is used to determine whether a parameter should be included in | |
| /// the URI when it has a default value. | |
| /// A function that compares two parameter values for inequality. | |
| /// | |
| /// Returns `true` if the values are considered different, and `false` if they | |
| /// are the same. This is used to determine whether a parameter should be | |
| /// included in the URI when it has a default value. |
|
go_router_builder PR: #11068 |
|
The analyzer is failing because of go_router_builder example Now, |
packages/go_router/CHANGELOG.md
Outdated
| @@ -1,3 +1,7 @@ | |||
| ## 17.2.0 | |||
|
|
|||
| - Adds `encoder`, `decoder` and `compare` parameters to `TypedQueryParameter` annotation for custom encoding, decoding and comparison of query parameters in `TypedGoRoute` constructors. | |||
There was a problem hiding this comment.
go_router has migrated to batch release, now we should add a new entry in pending_changelogs folder. the ci also hinted this.
There was a problem hiding this comment.
Oh okay, I changed it in Use batch release, let me know if that's correct
| /// The returned string is escaped to be URL-safe. For example, a parameter | ||
| /// value of `'field with space'` will generate a query parameter value of | ||
| /// `'field+with+space'`. | ||
| final String? Function(T?)? encoder; |
There was a problem hiding this comment.
we should typedef this. also what does returning null does here? and in what case will null to be feed into this. we should document these behavior in the typedef
There was a problem hiding this comment.
Good point, I made the parameter non-nullable in Better documentation
| /// A function that converts a string from the URI to a parameter value. | ||
| final T? Function(String?)? decoder; | ||
|
|
||
| /// A function that compares two parameter values for equality. |
There was a problem hiding this comment.
can you talk a bit more why this is needed?
There was a problem hiding this comment.
Let me know if that's good enough or not Better documentation
3e95760 to
624a61b
Compare
Part of
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