Skip to content

Commit

Permalink
[go_router_builder] Fixes issue when using query parameters that caus…
Browse files Browse the repository at this point in the history
…ed a nullable error
  • Loading branch information
Karibash committed Feb 28, 2025
1 parent 9744c9d commit 5f7553a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 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.8.2

- Fixes issue when using query parameters that caused a nullable error

## 2.8.1

- Fixes an issue when navigate to router with invalid params
Expand Down
8 changes: 5 additions & 3 deletions packages/go_router_builder/lib/src/type_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ String _stateValueAccess(ParameterElement element, Set<String> pathParameters) {
}

late String access;
final String suffix =
!element.type.isNullableType && !element.hasDefaultValue ? '!' : '';
if (pathParameters.contains(element.name)) {
access =
'pathParameters[${escapeDartString(element.name)}]${element.isRequired ? '!' : ''}';
access = 'pathParameters[${escapeDartString(element.name)}]$suffix';
} else {
access = 'uri.queryParameters[${escapeDartString(element.name.kebab)}]';
access =
'uri.queryParameters[${escapeDartString(element.name.kebab)}]$suffix';
}

return access;
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.8.1
version: 2.8.2
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 @@ -7,7 +7,7 @@ extension $NonNullableRequiredParamNotInPathExtension
on NonNullableRequiredParamNotInPath {
static NonNullableRequiredParamNotInPath _fromState(GoRouterState state) =>
NonNullableRequiredParamNotInPath(
id: int.parse(state.uri.queryParameters['id'])!,
id: int.parse(state.uri.queryParameters['id']!)!,
);

String get location => GoRouteData.$location(
Expand Down

0 comments on commit 5f7553a

Please sign in to comment.