-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router] Make queryParams a Map<String, dynamic>
#2392
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
[go_router] Make queryParams a Map<String, dynamic>
#2392
Conversation
…t-of-query-parameters # Conflicts: # packages/go_router/CHANGELOG.md
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.
code looks good, just need a bit more test.
| expect(configuration.namedLocation('SNAKE_CASE'), '/hij?'); | ||
| }); | ||
|
|
||
| test( |
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.
Can you add a test in go_router_test.dart to test the entire flow from context.goNamed() to the actual page is built with the correct query params?
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.
Thanks for the suggestion, while writing the test, I actually faced an issue/bug:
If you run this code snippet:
final uri = Uri(path: 'a/b/', queryParameters: {'q1': 'v1', 'q2': ['v2', 'v3']});
print(uri.queryParametersAll);
print(uri.queryParameters);It will log
{q1: [v1], q2: [v2, v3]}
{q1: v1, q2: v3}
Because of that, only carrying around queryParams is not enough, I had to add queryParametersAll everywhere.
Do you want me to remove queryParams as the data is now kind of duplicated? This would be a breaking change I think.
Or I could create getters Map<String, dynamic> get queryParams to not duplicate stored data and not introduce a breaking change?
What do you think?
…eters # Conflicts: # packages/go_router/CHANGELOG.md # packages/go_router/pubspec.yaml
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.
Can you fix the merge error and merge conflict ? also the build need to pass before this can merge
|
|
||
| - Allows `Map<String, dynamic>` maps as `queryParams` of `goNamed`, `replacedName`, `pushNamed` and `namedLocation`. | ||
|
|
||
| ## 4.2.5 |
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.
This seems to be merging error?
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.
I fixed the merge conflict in 13e6cb1
I'm working on fixing go_router_builder
…eters # Conflicts: # packages/go_router/CHANGELOG.md # packages/go_router/pubspec.yaml
|
@chunhtai I should have fixed the linter now |
|
Good idea, in my job when we need to give a widget a parameter that's not a String we use |
…t-of-query-parameters # Conflicts: # packages/go_router/CHANGELOG.md
|
Hello @chunhtai , is there something else I should do about this PR ? |
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.
LGTM, just some nits
| /// Query parameters for the matched route. | ||
| final Map<String, String> queryParams; | ||
|
|
||
| /// Query parameters for the matched route. |
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.
Can you add a bit more explanation on whats different between this and queryParams?
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.
I tried to write a better documentation in d9f9315
Tell me if there is something to change
| routes: configuration.routes, | ||
| parentFullpath: '', | ||
| parentSubloc: '', | ||
| // Here, if the request is `a/b/?q1=v1&q2=v2&q2=v3`; |
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.
This comment feel a bit out of place, maybe put this is doc string of the class property instead?
| final GoRouter router = await createRouter(routes, tester); | ||
| router.go('/login/'); | ||
| final List<RouteMatch> matches = router.routerDelegate.matches.matches; | ||
| print(matches); |
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.
nice catch!
packages/go_router/CHANGELOG.md
Outdated
| @@ -1,5 +1,6 @@ | |||
| ## NEXT | |||
| ## 4.2.8 | |||
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.
Shouldn't this be 4.3.0 since this adds a new parameter to GoRouterState?
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.
I changed the version number in e722483
|
|
||
| final GoRouter router = await createRouter(routes, tester); | ||
|
|
||
| router.goNamed('page', queryParams: const <String, dynamic>{ |
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.
Can we add a test for go() too?
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.
Yep, I added a test in d9f9315
|
Just confirming, there's still work to do in go_router_builder (flutter/flutter#108437), but this won't break it? |
Hum, I might be wrong but I think we are good.
But yeah, in order to do flutter/flutter#108437, we should merge this PR first, so |
…eters # Conflicts: # packages/go_router/CHANGELOG.md # packages/go_router/pubspec.yaml
…t-of-query-parameters # Conflicts: # packages/go_router/CHANGELOG.md
|
@johnpryan Do you want me to do anything else on this PR? |
|
cc @johnpryan |
…t-of-query-parameters # Conflicts: # packages/go_router/CHANGELOG.md # packages/go_router/pubspec.yaml # packages/go_router/test/test_helpers.dart
|
@chunhtai Isn't this technically a breaking change since we changed method signatures? Should we target the v5 branch instead? |
|
@loic-sharma I don't think this will be breaking you can upward cast type in map without addition code. Or is there a use case I may be missing? |
|
Yup never mind my concern. This works as expected too: |
|
i see you already support map<String, dynamic> but queryParams in GoRouterState is still map<String, String> so i can't get data, it throws type 'SomethingLikeEnum' is not a subtype of type 'Iterable' |
|
@Sotatek-PhiPham You can use |
|
i tried queryParametersAll but it is Map<String, List>. I am using go router version 4.4.1 |
|
Yes, it uses
And
|
|
still cant get bool in queryParameters , i need bool.parse to convert string to bool , is this possible to make queryParameters getter to <String, dynamic> ? |
|
the dynamic is not meant to be use for various type. It is to support list query parameter. https://api.flutter.dev/flutter/dart-core/Uri/queryParametersAll.html locking this issue |
fixes flutter/flutter#108390
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.