File tree Expand file tree Collapse file tree 7 files changed +130
-2
lines changed
packages/go_router_builder Expand file tree Collapse file tree 7 files changed +130
-2
lines changed Original file line number Diff line number Diff line change 1+
2+ ## 2.7.3
3+
4+ - Fixes an issue when using a not null List or Set param.
5+
16## 2.7.2
27
38- Supports the latest ` package:analyzer ` and ` package:source_gen ` .
Original file line number Diff line number Diff line change @@ -273,18 +273,27 @@ class _TypeHelperIterable extends _TypeHelper {
273273
274274 // get correct type for iterable
275275 String iterableCaster = '' ;
276+ String fallBack = '' ;
276277 if (const TypeChecker .fromRuntime (List )
277278 .isAssignableFromType (parameterElement.type)) {
278279 iterableCaster = '.toList()' ;
280+ if (! parameterElement.type.isNullableType &&
281+ ! parameterElement.hasDefaultValue) {
282+ fallBack = '?? const []' ;
283+ }
279284 } else if (const TypeChecker .fromRuntime (Set )
280285 .isAssignableFromType (parameterElement.type)) {
281286 iterableCaster = '.toSet()' ;
287+ if (! parameterElement.type.isNullableType &&
288+ ! parameterElement.hasDefaultValue) {
289+ fallBack = '?? const {}' ;
290+ }
282291 }
283292
284293 return '''
285294state.uri.queryParametersAll[
286295 ${escapeDartString (parameterElement .name .kebab )}]
287- ?.map($entriesTypeDecoder )$iterableCaster ''' ;
296+ ?.map($entriesTypeDecoder )$iterableCaster $ fallBack ''' ;
288297 }
289298 return '''
290299state.uri.queryParametersAll[${escapeDartString (parameterElement .name .kebab )}]''' ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ name: go_router_builder
22description : >-
33 A builder that supports generated strongly-typed route helpers for
44 package:go_router
5- version : 2.7.2
5+ version : 2.7.3
66repository : https://github.com/flutter/packages/tree/main/packages/go_router_builder
77issue_tracker : https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22
88
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors. All rights reserved.
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:go_router/go_router.dart' ;
6+
7+ @TypedGoRoute < ListRoute > (path: '/list-route' )
8+ class ListRoute extends GoRouteData {
9+ ListRoute ({
10+ required this .ids,
11+ this .nullableIds,
12+ this .idsWithDefaultValue = const < int > [0 ],
13+ });
14+ final List <int > ids;
15+ final List <int >? nullableIds;
16+ final List <int > idsWithDefaultValue;
17+ }
Original file line number Diff line number Diff line change 1+ RouteBase get $listRoute => GoRouteData.$route(
2+ path: '/list-route',
3+ factory: $ListRouteExtension._fromState,
4+ );
5+
6+ extension $ListRouteExtension on ListRoute {
7+ static ListRoute _fromState(GoRouterState state) => ListRoute(
8+ ids: state.uri.queryParametersAll['ids']?.map(int.parse).toList() ??
9+ const [],
10+ nullableIds: state.uri.queryParametersAll['nullable-ids']
11+ ?.map(int.parse)
12+ .toList(),
13+ idsWithDefaultValue: state
14+ .uri.queryParametersAll['ids-with-default-value']
15+ ?.map(int.parse)
16+ .toList() ??
17+ const <int>[0],
18+ );
19+
20+ String get location => GoRouteData.$location(
21+ '/list-route',
22+ queryParams: {
23+ 'ids': ids.map((e) => e.toString()).toList(),
24+ if (nullableIds != null)
25+ 'nullable-ids': nullableIds?.map((e) => e.toString()).toList(),
26+ if (idsWithDefaultValue != const <int>[0])
27+ 'ids-with-default-value':
28+ idsWithDefaultValue.map((e) => e.toString()).toList(),
29+ },
30+ );
31+
32+ void go(BuildContext context) => context.go(location);
33+
34+ Future<T?> push<T>(BuildContext context) => context.push<T>(location);
35+
36+ void pushReplacement(BuildContext context) =>
37+ context.pushReplacement(location);
38+
39+ void replace(BuildContext context) => context.replace(location);
40+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors. All rights reserved.
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:go_router/go_router.dart' ;
6+
7+ @TypedGoRoute < SetRoute > (path: '/set-route' )
8+ class SetRoute extends GoRouteData {
9+ SetRoute ({
10+ required this .ids,
11+ this .nullableIds,
12+ this .idsWithDefaultValue = const < int > {0 },
13+ });
14+ final Set <int > ids;
15+ final Set <int >? nullableIds;
16+ final Set <int > idsWithDefaultValue;
17+ }
Original file line number Diff line number Diff line change 1+ RouteBase get $setRoute => GoRouteData.$route(
2+ path: '/set-route',
3+ factory: $SetRouteExtension._fromState,
4+ );
5+
6+ extension $SetRouteExtension on SetRoute {
7+ static SetRoute _fromState(GoRouterState state) => SetRoute(
8+ ids: state.uri.queryParametersAll['ids']?.map(int.parse).toSet() ??
9+ const {},
10+ nullableIds: state.uri.queryParametersAll['nullable-ids']
11+ ?.map(int.parse)
12+ .toSet(),
13+ idsWithDefaultValue: state
14+ .uri.queryParametersAll['ids-with-default-value']
15+ ?.map(int.parse)
16+ .toSet() ??
17+ const <int>{0},
18+ );
19+
20+ String get location => GoRouteData.$location(
21+ '/set-route',
22+ queryParams: {
23+ 'ids': ids.map((e) => e.toString()).toList(),
24+ if (nullableIds != null)
25+ 'nullable-ids': nullableIds?.map((e) => e.toString()).toList(),
26+ if (idsWithDefaultValue != const <int>{0})
27+ 'ids-with-default-value':
28+ idsWithDefaultValue.map((e) => e.toString()).toList(),
29+ },
30+ );
31+
32+ void go(BuildContext context) => context.go(location);
33+
34+ Future<T?> push<T>(BuildContext context) => context.push<T>(location);
35+
36+ void pushReplacement(BuildContext context) =>
37+ context.pushReplacement(location);
38+
39+ void replace(BuildContext context) => context.replace(location);
40+ }
You can’t perform that action at this time.
0 commit comments