Skip to content

Commit cdb9bc6

Browse files
[go_router_builder] Include required and positional query parameters in the location (#4163)
Fixes flutter/flutter#128483
1 parent afe2f05 commit cdb9bc6

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

packages/go_router_builder/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.1
2+
3+
* Fixes a bug that the required/positional parameters are not added to query parameters correctly.
4+
15
## 2.1.0
26

37
* Supports required/positional parameters that are not in the path.

packages/go_router_builder/lib/src/route_config.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,15 +441,15 @@ GoRouteData.\$route(
441441

442442
late final List<ParameterElement> _ctorParams =
443443
_ctor.parameters.where((ParameterElement element) {
444-
if (element.isRequired && !element.isExtraField) {
444+
if (_pathParams.contains(element.name)) {
445445
return true;
446446
}
447447
return false;
448448
}).toList();
449449

450450
late final List<ParameterElement> _ctorQueryParams = _ctor.parameters
451451
.where((ParameterElement element) =>
452-
element.isOptional && !element.isExtraField)
452+
!_pathParams.contains(element.name) && !element.isExtraField)
453453
.toList();
454454

455455
ConstructorElement get _ctor {

packages/go_router_builder/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: go_router_builder
22
description: >-
33
A builder that supports generated strongly-typed route helpers for
44
package:go_router
5-
version: 2.1.0
5+
version: 2.1.1
66
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
77
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22
88

packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ extension $NullableRequiredParamNotInPathExtension
6868
6969
String get location => GoRouteData.$location(
7070
'bob',
71+
queryParams: {
72+
if (id != null) 'id': id!.toString(),
73+
},
7174
);
7275
7376
void go(BuildContext context) => context.go(location);
@@ -108,6 +111,9 @@ extension $NonNullableRequiredParamNotInPathExtension
108111
109112
String get location => GoRouteData.$location(
110113
'bob',
114+
queryParams: {
115+
'id': id.toString(),
116+
},
111117
);
112118
113119
void go(BuildContext context) => context.go(location);

0 commit comments

Comments
 (0)