Skip to content

Comments

[go_router] Add encoder,decoder and compare parameters to TypedQueryParameter#11067

Open
ValentinVignal wants to merge 4 commits intoflutter:mainfrom
ValentinVignal:go-router/support-custom-types
Open

[go_router] Add encoder,decoder and compare parameters to TypedQueryParameter#11067
ValentinVignal wants to merge 4 commits intoflutter:mainfrom
ValentinVignal:go-router/support-custom-types

Conversation

@ValentinVignal
Copy link
Contributor

Part of

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

@ValentinVignal ValentinVignal changed the title [go_router] Add encoder,decoder and compare parameters to `TypedQueryParameter [go_router] Add encoder,decoder and compare parameters to TypedQueryParameter Feb 19, 2026
@github-actions github-actions bot added p: go_router triage-framework Should be looked at in framework triage labels Feb 19, 2026
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 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.

Comment on lines 666 to 670
/// 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.

Choose a reason for hiding this comment

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

medium

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.

Suggested change
/// 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.

@ValentinVignal
Copy link
Contributor Author

go_router_builder PR: #11068

@ValentinVignal
Copy link
Contributor Author

The analyzer is failing because of go_router_builder example

Got dependencies in `./example`.
Running command: "dart analyze --fatal-infos" in /b/s/w/ir/x/w/packages/packages/go_router_builder
Analyzing go_router_builder...

warning - example/lib/typed_query_parameter_example.dart:30:5 - The type argument(s) of the constructor 'TypedQueryParameter' can't be inferred. Use explicit type argument(s) for 'TypedQueryParameter'. - inference_failure_on_instance_creation
warning - example/lib/typed_query_parameter_example.dart:31:5 - The type argument(s) of the constructor 'TypedQueryParameter' can't be inferred. Use explicit type argument(s) for 'TypedQueryParameter'. - inference_failure_on_instance_creation
warning - example/lib/typed_query_parameter_example.dart:33:5 - The type argument(s) of the constructor 'TypedQueryParameter' can't be inferred. Use explicit type argument(s) for 'TypedQueryParameter'. - inference_failure_on_instance_creation
warning - test_inputs/typed_query_parameter.dart:13:5 - The type argument(s) of the constructor 'TypedQueryParameter' can't be inferred. Use explicit type argument(s) for 'TypedQueryParameter'. - inference_failure_on_instance_creation
warning - test_inputs/typed_query_parameter.dart:14:5 - The type argument(s) of the constructor 'TypedQueryParameter' can't be inferred. Use explicit type argument(s) for 'TypedQueryParameter'. - inference_failure_on_instance_creation

Now, TypedQueryParameter takes a generic type. I've updated those in the go_router_builder PR: #11068.
Should I update them in this PR?

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

Choose a reason for hiding this comment

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

go_router has migrated to batch release, now we should add a new entry in pending_changelogs folder. the ci also hinted this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

can you talk a bit more why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if that's good enough or not Better documentation

@ValentinVignal ValentinVignal force-pushed the go-router/support-custom-types branch from 3e95760 to 624a61b Compare February 23, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants