mirror of
https://github.com/flutter/packages.git
synced 2025-07-02 08:34:31 +08:00
[go_router_builder] Include required and positional query parameters in the location (#4163)
Fixes https://github.com/flutter/flutter/issues/128483
This commit is contained in:
@ -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.
|
||||
|
@ -441,7 +441,7 @@ 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;
|
||||
@ -449,7 +449,7 @@ GoRouteData.\$route(
|
||||
|
||||
late final List<ParameterElement> _ctorQueryParams = _ctor.parameters
|
||||
.where((ParameterElement element) =>
|
||||
element.isOptional && !element.isExtraField)
|
||||
!_pathParams.contains(element.name) && !element.isExtraField)
|
||||
.toList();
|
||||
|
||||
ConstructorElement get _ctor {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
@ -108,6 +111,9 @@ extension $NonNullableRequiredParamNotInPathExtension
|
||||
|
||||
String get location => GoRouteData.$location(
|
||||
'bob',
|
||||
queryParams: {
|
||||
'id': id.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
void go(BuildContext context) => context.go(location);
|
||||
|
Reference in New Issue
Block a user