Skip to content

Commit

Permalink
[go_router_builder] Include required and positional query parameters …
Browse files Browse the repository at this point in the history
…in the location (flutter#4163)

Fixes flutter#128483
  • Loading branch information
ValentinVignal authored Jun 9, 2023
1 parent afe2f05 commit cdb9bc6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.1

* Fixes a bug that the required/positional parameters are not added to query parameters correctly.

## 2.1.0

* Supports required/positional parameters that are not in the path.
Expand Down
4 changes: 2 additions & 2 deletions packages/go_router_builder/lib/src/route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,15 @@ GoRouteData.\$route(

late final List<ParameterElement> _ctorParams =
_ctor.parameters.where((ParameterElement element) {
if (element.isRequired && !element.isExtraField) {
if (_pathParams.contains(element.name)) {
return true;
}
return false;
}).toList();

late final List<ParameterElement> _ctorQueryParams = _ctor.parameters
.where((ParameterElement element) =>
element.isOptional && !element.isExtraField)
!_pathParams.contains(element.name) && !element.isExtraField)
.toList();

ConstructorElement get _ctor {
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: go_router_builder
description: >-
A builder that supports generated strongly-typed route helpers for
package:go_router
version: 2.1.0
version: 2.1.1
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ extension $NullableRequiredParamNotInPathExtension
String get location => GoRouteData.$location(
'bob',
queryParams: {
if (id != null) 'id': id!.toString(),
},
);
void go(BuildContext context) => context.go(location);
Expand Down Expand Up @@ -108,6 +111,9 @@ extension $NonNullableRequiredParamNotInPathExtension
String get location => GoRouteData.$location(
'bob',
queryParams: {
'id': id.toString(),
},
);
void go(BuildContext context) => context.go(location);
Expand Down

0 comments on commit cdb9bc6

Please sign in to comment.