From 1d2a3ba968107eb28889a73e6a82a4445022115b Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Tue, 27 Dec 2022 11:45:44 -0800 Subject: [PATCH 01/11] update extra This reverts commit 36213a45c8f7cedb4e6b4d7d650eac2b1802d341. remove extra update log update tests update Update CHANGELOG.md lint lint --- packages/go_router_builder/CHANGELOG.md | 4 ++ .../example/lib/all_types.g.dart | 66 ++++++++++++------- .../go_router_builder/example/lib/main.dart | 2 +- .../go_router_builder/example/lib/main.g.dart | 30 ++++++--- .../example/lib/simple_example.g.dart | 12 ++-- .../lib/src/route_config.dart | 6 +- packages/go_router_builder/pubspec.yaml | 2 +- .../_go_router_builder_test_input.dart | 6 +- 8 files changed, 86 insertions(+), 42 deletions(-) diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 13cb7d76ad60..dcdde167d629 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.16 + +* Update router_config to not passing `extra` unconditionally. + ## 1.0.15 * Avoids using deprecated DartType.element2. diff --git a/packages/go_router_builder/example/lib/all_types.g.dart b/packages/go_router_builder/example/lib/all_types.g.dart index 4aeb4173f408..8418eca3a5e1 100644 --- a/packages/go_router_builder/example/lib/all_types.g.dart +++ b/packages/go_router_builder/example/lib/all_types.g.dart @@ -71,9 +71,11 @@ extension $AllTypesBaseRouteExtension on AllTypesBaseRoute { '/', ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $BigIntRouteExtension on BigIntRoute { @@ -90,9 +92,11 @@ extension $BigIntRouteExtension on BigIntRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $BoolRouteExtension on BoolRoute { @@ -109,9 +113,11 @@ extension $BoolRouteExtension on BoolRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $DateTimeRouteExtension on DateTimeRoute { @@ -130,9 +136,11 @@ extension $DateTimeRouteExtension on DateTimeRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $DoubleRouteExtension on DoubleRoute { @@ -149,9 +157,11 @@ extension $DoubleRouteExtension on DoubleRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $IntRouteExtension on IntRoute { @@ -167,9 +177,11 @@ extension $IntRouteExtension on IntRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $NumRouteExtension on NumRoute { @@ -185,9 +197,11 @@ extension $NumRouteExtension on NumRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $EnumRouteExtension on EnumRoute { @@ -206,9 +220,11 @@ extension $EnumRouteExtension on EnumRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $EnhancedEnumRouteExtension on EnhancedEnumRoute { @@ -227,9 +243,11 @@ extension $EnhancedEnumRouteExtension on EnhancedEnumRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $StringRouteExtension on StringRoute { @@ -245,9 +263,11 @@ extension $StringRouteExtension on StringRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $UriRouteExtension on UriRoute { @@ -263,9 +283,11 @@ extension $UriRouteExtension on UriRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } const _$PersonDetailsEnumMap = { diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart index 8311655b74a1..cc40fbeeb0cf 100644 --- a/packages/go_router_builder/example/lib/main.dart +++ b/packages/go_router_builder/example/lib/main.dart @@ -232,7 +232,7 @@ class PersonScreen extends StatelessWidget { person.id, entry.key, $extra: ++_extraClickCount, - ).go(context), + ).go(context, extra: _extraClickCount), child: const Text('With extra...'), ), onTap: () => PersonDetailsRoute(family.id, person.id, entry.key) diff --git a/packages/go_router_builder/example/lib/main.g.dart b/packages/go_router_builder/example/lib/main.g.dart index 0f87baaff2ac..9ae32607cae4 100644 --- a/packages/go_router_builder/example/lib/main.g.dart +++ b/packages/go_router_builder/example/lib/main.g.dart @@ -43,9 +43,11 @@ extension $HomeRouteExtension on HomeRoute { '/', ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $FamilyRouteExtension on FamilyRoute { @@ -57,9 +59,11 @@ extension $FamilyRouteExtension on FamilyRoute { '/family/${Uri.encodeComponent(fid)}', ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $PersonRouteExtension on PersonRoute { @@ -72,9 +76,11 @@ extension $PersonRouteExtension on PersonRoute { '/family/${Uri.encodeComponent(fid)}/person/${Uri.encodeComponent(pid.toString())}', ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $PersonDetailsRouteExtension on PersonDetailsRoute { @@ -90,9 +96,11 @@ extension $PersonDetailsRouteExtension on PersonDetailsRoute { '/family/${Uri.encodeComponent(fid)}/person/${Uri.encodeComponent(pid.toString())}/details/${Uri.encodeComponent(_$PersonDetailsEnumMap[details]!)}', ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } const _$PersonDetailsEnumMap = { @@ -123,7 +131,9 @@ extension $LoginRouteExtension on LoginRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } diff --git a/packages/go_router_builder/example/lib/simple_example.g.dart b/packages/go_router_builder/example/lib/simple_example.g.dart index b3ad338d4f37..c86b35db792b 100644 --- a/packages/go_router_builder/example/lib/simple_example.g.dart +++ b/packages/go_router_builder/example/lib/simple_example.g.dart @@ -30,9 +30,11 @@ extension $HomeRouteExtension on HomeRoute { '/', ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } extension $FamilyRouteExtension on FamilyRoute { @@ -44,7 +46,9 @@ extension $FamilyRouteExtension on FamilyRoute { '/family/${Uri.encodeComponent(familyId)}', ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index d58aac54f68e..776a20d5836c 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -142,9 +142,11 @@ extension $_extensionName on $_className { String get location => GoRouteData.\$location($_locationArgs,$_locationQueryParams); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } '''; diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 60a2c3ebe2cc..6e1083935e38 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -2,7 +2,7 @@ name: go_router_builder description: >- A builder that supports generated strongly-typed route helpers for package:go_router -version: 1.0.15 +version: 1.0.16 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 diff --git a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart index ca204efaaf94..2187382474bc 100644 --- a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart +++ b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart @@ -86,9 +86,11 @@ extension $EnumParamExtension on EnumParam { '/${Uri.encodeComponent(_$EnumTestEnumMap[y]!)}', ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context, {Object? extra}) => + context.go(location, extra: extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context, {Object? extra}) => + context.push(location, extra: extra); } const _$EnumTestEnumMap = { From f28552744cf3de390305aa978c7c0233bd7ea60d Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Tue, 7 Feb 2023 17:07:38 -0800 Subject: [PATCH 02/11] test Revert "test" This reverts commit d748242967a0a3805364d438bc81f39cf3804cc7. Update main.dart --- packages/go_router_builder/example/lib/main.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart index 3a49b8b7296b..90aa65d9c007 100644 --- a/packages/go_router_builder/example/lib/main.dart +++ b/packages/go_router_builder/example/lib/main.dart @@ -232,8 +232,7 @@ class PersonScreen extends StatelessWidget { family.id, person.id, entry.key, - $extra: ++_extraClickCount, - ).go(context, extra: _extraClickCount), + ).go(context, extra: ++_extraClickCount), child: const Text('With extra...'), ), onTap: () => PersonDetailsRoute(family.id, person.id, entry.key) From 0970928f3b6fda4b7ba1ff9980e1d073a1b63f4f Mon Sep 17 00:00:00 2001 From: hangyu Date: Fri, 17 Feb 2023 17:00:01 -0800 Subject: [PATCH 03/11] Update packages/go_router_builder/CHANGELOG.md Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com> --- packages/go_router_builder/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 4514befe062c..4be227a7e576 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,6 +1,6 @@ ## 1.0.17 -* Update router_config to not passing `extra` unconditionally. +* Updates router_config to not passing itself as `extra`. ## 1.0.16 From 28fc4d142c5bf23c6bc2bacaf0fbd6ce40d4bc2d Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Sat, 25 Feb 2023 17:44:13 -0800 Subject: [PATCH 04/11] update extra --- .../go_router_builder/example/lib/main.dart | 3 +- .../go_router_builder/example/lib/main.g.dart | 30 +++++++------------ .../lib/src/route_config.dart | 13 ++++---- .../_go_router_builder_test_input.dart | 6 ++-- 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart index 90aa65d9c007..f6a64edf1842 100644 --- a/packages/go_router_builder/example/lib/main.dart +++ b/packages/go_router_builder/example/lib/main.dart @@ -232,7 +232,8 @@ class PersonScreen extends StatelessWidget { family.id, person.id, entry.key, - ).go(context, extra: ++_extraClickCount), + $extra: ++_extraClickCount, + ).go(context), child: const Text('With extra...'), ), onTap: () => PersonDetailsRoute(family.id, person.id, entry.key) diff --git a/packages/go_router_builder/example/lib/main.g.dart b/packages/go_router_builder/example/lib/main.g.dart index 9ae32607cae4..b909df66db79 100644 --- a/packages/go_router_builder/example/lib/main.g.dart +++ b/packages/go_router_builder/example/lib/main.g.dart @@ -43,11 +43,9 @@ extension $HomeRouteExtension on HomeRoute { '/', ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $FamilyRouteExtension on FamilyRoute { @@ -59,11 +57,9 @@ extension $FamilyRouteExtension on FamilyRoute { '/family/${Uri.encodeComponent(fid)}', ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $PersonRouteExtension on PersonRoute { @@ -76,11 +72,9 @@ extension $PersonRouteExtension on PersonRoute { '/family/${Uri.encodeComponent(fid)}/person/${Uri.encodeComponent(pid.toString())}', ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $PersonDetailsRouteExtension on PersonDetailsRoute { @@ -96,11 +90,9 @@ extension $PersonDetailsRouteExtension on PersonDetailsRoute { '/family/${Uri.encodeComponent(fid)}/person/${Uri.encodeComponent(pid.toString())}/details/${Uri.encodeComponent(_$PersonDetailsEnumMap[details]!)}', ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location, extra: $extra); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location, extra: $extra); } const _$PersonDetailsEnumMap = { @@ -131,9 +123,7 @@ extension $LoginRouteExtension on LoginRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index 776a20d5836c..2a025cfb0212 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -142,11 +142,11 @@ extension $_extensionName on $_className { String get location => GoRouteData.\$location($_locationArgs,$_locationQueryParams); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => + context.go(location${_extraParam != null ? ', extra: ${_decodeFor(_extraParam!)}' : ''}); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => + context.go(location${_extraParam != null ? ', extra: ${_decodeFor(_extraParam!)}' : ''}); } '''; @@ -186,6 +186,8 @@ GoRoute get $_routeGetterName => ${_routeDefinition()}; yield _enumMapConst(enumParamType); } } + ParameterElement? get _extraParam => _ctor.parameters + .singleWhereOrNull((ParameterElement element) => element.isExtraField); String get _newFromState { final StringBuffer buffer = StringBuffer('=>'); @@ -193,8 +195,7 @@ GoRoute get $_routeGetterName => ${_routeDefinition()}; buffer.writeln('const '); } - final ParameterElement? extraParam = _ctor.parameters - .singleWhereOrNull((ParameterElement element) => element.isExtraField); + final ParameterElement? extraParam = _extraParam; buffer.writeln('$_className('); for (final ParameterElement param in [ diff --git a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart index 2187382474bc..8b87a1a7692e 100644 --- a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart +++ b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart @@ -86,11 +86,9 @@ extension $EnumParamExtension on EnumParam { '/${Uri.encodeComponent(_$EnumTestEnumMap[y]!)}', ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } const _$EnumTestEnumMap = { From faab96bd74449fb1cd661b08c7fa2e9e7ba6a7cf Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Sat, 25 Feb 2023 17:56:15 -0800 Subject: [PATCH 05/11] update --- .../example/lib/all_types.g.dart | 66 +++++++------------ .../example/lib/simple_example.g.dart | 12 ++-- .../lib/src/route_config.dart | 4 +- .../_go_router_builder_test_input.dart | 48 ++++++++++++++ 4 files changed, 76 insertions(+), 54 deletions(-) diff --git a/packages/go_router_builder/example/lib/all_types.g.dart b/packages/go_router_builder/example/lib/all_types.g.dart index 8418eca3a5e1..597dcded5e94 100644 --- a/packages/go_router_builder/example/lib/all_types.g.dart +++ b/packages/go_router_builder/example/lib/all_types.g.dart @@ -71,11 +71,9 @@ extension $AllTypesBaseRouteExtension on AllTypesBaseRoute { '/', ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $BigIntRouteExtension on BigIntRoute { @@ -92,11 +90,9 @@ extension $BigIntRouteExtension on BigIntRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $BoolRouteExtension on BoolRoute { @@ -113,11 +109,9 @@ extension $BoolRouteExtension on BoolRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $DateTimeRouteExtension on DateTimeRoute { @@ -136,11 +130,9 @@ extension $DateTimeRouteExtension on DateTimeRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $DoubleRouteExtension on DoubleRoute { @@ -157,11 +149,9 @@ extension $DoubleRouteExtension on DoubleRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $IntRouteExtension on IntRoute { @@ -177,11 +167,9 @@ extension $IntRouteExtension on IntRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $NumRouteExtension on NumRoute { @@ -197,11 +185,9 @@ extension $NumRouteExtension on NumRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $EnumRouteExtension on EnumRoute { @@ -220,11 +206,9 @@ extension $EnumRouteExtension on EnumRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $EnhancedEnumRouteExtension on EnhancedEnumRoute { @@ -243,11 +227,9 @@ extension $EnhancedEnumRouteExtension on EnhancedEnumRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $StringRouteExtension on StringRoute { @@ -263,11 +245,9 @@ extension $StringRouteExtension on StringRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $UriRouteExtension on UriRoute { @@ -283,11 +263,9 @@ extension $UriRouteExtension on UriRoute { }, ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } const _$PersonDetailsEnumMap = { diff --git a/packages/go_router_builder/example/lib/simple_example.g.dart b/packages/go_router_builder/example/lib/simple_example.g.dart index c86b35db792b..58e229a28171 100644 --- a/packages/go_router_builder/example/lib/simple_example.g.dart +++ b/packages/go_router_builder/example/lib/simple_example.g.dart @@ -30,11 +30,9 @@ extension $HomeRouteExtension on HomeRoute { '/', ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } extension $FamilyRouteExtension on FamilyRoute { @@ -46,9 +44,7 @@ extension $FamilyRouteExtension on FamilyRoute { '/family/${Uri.encodeComponent(familyId)}', ); - void go(BuildContext context, {Object? extra}) => - context.go(location, extra: extra); + void go(BuildContext context) => context.go(location); - void push(BuildContext context, {Object? extra}) => - context.push(location, extra: extra); + void push(BuildContext context) => context.push(location); } diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index 2a025cfb0212..fda46d5be307 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -143,10 +143,10 @@ extension $_extensionName on $_className { String get location => GoRouteData.\$location($_locationArgs,$_locationQueryParams); void go(BuildContext context) => - context.go(location${_extraParam != null ? ', extra: ${_decodeFor(_extraParam!)}' : ''}); + context.go(location${_extraParam != null ? ', extra: $extraFieldName' : ''}); void push(BuildContext context) => - context.go(location${_extraParam != null ? ', extra: ${_decodeFor(_extraParam!)}' : ''}); + context.push(location${_extraParam != null ? ', extra: $extraFieldName' : ''}); } '''; diff --git a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart index 8b87a1a7692e..e401c5243030 100644 --- a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart +++ b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart @@ -116,3 +116,51 @@ enum EnumTest { const EnumTest(this.x); final int x; } + + +@ShouldGenerate(r''' +GoRoute get $enumParam => GoRouteData.$route( + path: '/:y', + factory: $EnumParamExtension._fromState, + ); + +extension $EnumParamExtension on EnumParam { + static EnumParam _fromState(GoRouterState state) => EnumParam( + y: _$EnumTestEnumMap._$fromName(state.params['y']!), + ); + + String get location => GoRouteData.$location( + '/${Uri.encodeComponent(_$EnumTestEnumMap[y]!)}', + ); + + void go(BuildContext context) => context.go(location); + + void push(BuildContext context) => context.push(location); +} + +const _$EnumTestEnumMap = { + EnumTest.a: 'a', + EnumTest.b: 'b', + EnumTest.c: 'c', +}; + +extension on Map { + T _$fromName(String value) => + entries.singleWhere((element) => element.value == value).key; +} +''') +@TypedGoRoute(path: '/:y') +class EnumParamWithExtra extends GoRouteData { + EnumParamWithExtra({required this.y, this.$extra}); + final EnumWithExtraTest y; + final int? $extra; +} + +enum EnumWithExtraTest { + a(1), + b(3), + c(5); + + const EnumWithExtraTest(this.x); + final int x; +} From cc28d6c2c2559732f90d499ae58b91bda37a8dce Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Sat, 25 Feb 2023 18:21:07 -0800 Subject: [PATCH 06/11] update --- .../example/lib/all_types.g.dart | 185 +++++++++++++++++- .../go_router_builder/example/lib/main.g.dart | 17 +- .../example/lib/simple_example.g.dart | 6 + .../_go_router_builder_test_input.dart | 62 +++--- 4 files changed, 232 insertions(+), 38 deletions(-) diff --git a/packages/go_router_builder/example/lib/all_types.g.dart b/packages/go_router_builder/example/lib/all_types.g.dart index 597dcded5e94..61f38b7aee92 100644 --- a/packages/go_router_builder/example/lib/all_types.g.dart +++ b/packages/go_router_builder/example/lib/all_types.g.dart @@ -60,6 +60,10 @@ GoRoute get $allTypesBaseRoute => GoRouteData.$route( path: 'uri-route/:requiredUriField', factory: $UriRouteExtension._fromState, ), + GoRouteData.$route( + path: 'iterable-route', + factory: $IterableRouteExtension._fromState, + ), ], ); @@ -74,6 +78,9 @@ extension $AllTypesBaseRouteExtension on AllTypesBaseRoute { void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $BigIntRouteExtension on BigIntRoute { @@ -93,6 +100,9 @@ extension $BigIntRouteExtension on BigIntRoute { void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $BoolRouteExtension on BoolRoute { @@ -100,18 +110,29 @@ extension $BoolRouteExtension on BoolRoute { requiredBoolField: _$boolConverter(state.params['requiredBoolField']!), boolField: _$convertMapValue('bool-field', state.queryParams, _$boolConverter), + boolFieldWithDefaultValue: _$convertMapValue( + 'bool-field-with-default-value', + state.queryParams, + _$boolConverter) ?? + true, ); String get location => GoRouteData.$location( '/bool-route/${Uri.encodeComponent(requiredBoolField.toString())}', queryParams: { if (boolField != null) 'bool-field': boolField!.toString(), + if (boolFieldWithDefaultValue != true) + 'bool-field-with-default-value': + boolFieldWithDefaultValue.toString(), }, ); void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $DateTimeRouteExtension on DateTimeRoute { @@ -133,6 +154,9 @@ extension $DateTimeRouteExtension on DateTimeRoute { void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $DoubleRouteExtension on DoubleRoute { @@ -140,54 +164,81 @@ extension $DoubleRouteExtension on DoubleRoute { requiredDoubleField: double.parse(state.params['requiredDoubleField']!), doubleField: _$convertMapValue('double-field', state.queryParams, double.parse), + doubleFieldWithDefaultValue: _$convertMapValue( + 'double-field-with-default-value', + state.queryParams, + double.parse) ?? + 1.0, ); String get location => GoRouteData.$location( '/double-route/${Uri.encodeComponent(requiredDoubleField.toString())}', queryParams: { if (doubleField != null) 'double-field': doubleField!.toString(), + if (doubleFieldWithDefaultValue != 1.0) + 'double-field-with-default-value': + doubleFieldWithDefaultValue.toString(), }, ); void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $IntRouteExtension on IntRoute { static IntRoute _fromState(GoRouterState state) => IntRoute( requiredIntField: int.parse(state.params['requiredIntField']!), intField: _$convertMapValue('int-field', state.queryParams, int.parse), + intFieldWithDefaultValue: _$convertMapValue( + 'int-field-with-default-value', state.queryParams, int.parse) ?? + 1, ); String get location => GoRouteData.$location( '/int-route/${Uri.encodeComponent(requiredIntField.toString())}', queryParams: { if (intField != null) 'int-field': intField!.toString(), + if (intFieldWithDefaultValue != 1) + 'int-field-with-default-value': intFieldWithDefaultValue.toString(), }, ); void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $NumRouteExtension on NumRoute { static NumRoute _fromState(GoRouterState state) => NumRoute( requiredNumField: num.parse(state.params['requiredNumField']!), numField: _$convertMapValue('num-field', state.queryParams, num.parse), + numFieldWithDefaultValue: _$convertMapValue( + 'num-field-with-default-value', state.queryParams, num.parse) ?? + 1, ); String get location => GoRouteData.$location( '/num-route/${Uri.encodeComponent(requiredNumField.toString())}', queryParams: { if (numField != null) 'num-field': numField!.toString(), + if (numFieldWithDefaultValue != 1) + 'num-field-with-default-value': numFieldWithDefaultValue.toString(), }, ); void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $EnumRouteExtension on EnumRoute { @@ -196,19 +247,30 @@ extension $EnumRouteExtension on EnumRoute { ._$fromName(state.params['requiredEnumField']!), enumField: _$convertMapValue( 'enum-field', state.queryParams, _$PersonDetailsEnumMap._$fromName), + enumFieldWithDefaultValue: _$convertMapValue( + 'enum-field-with-default-value', + state.queryParams, + _$PersonDetailsEnumMap._$fromName) ?? + PersonDetails.favoriteFood, ); String get location => GoRouteData.$location( '/enum-route/${Uri.encodeComponent(_$PersonDetailsEnumMap[requiredEnumField]!)}', queryParams: { if (enumField != null) - 'enum-field': _$PersonDetailsEnumMap[enumField!]!, + 'enum-field': _$PersonDetailsEnumMap[enumField!], + if (enumFieldWithDefaultValue != PersonDetails.favoriteFood) + 'enum-field-with-default-value': + _$PersonDetailsEnumMap[enumFieldWithDefaultValue], }, ); void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $EnhancedEnumRouteExtension on EnhancedEnumRoute { @@ -217,37 +279,56 @@ extension $EnhancedEnumRouteExtension on EnhancedEnumRoute { ._$fromName(state.params['requiredEnumField']!), enumField: _$convertMapValue( 'enum-field', state.queryParams, _$SportDetailsEnumMap._$fromName), + enumFieldWithDefaultValue: _$convertMapValue( + 'enum-field-with-default-value', + state.queryParams, + _$SportDetailsEnumMap._$fromName) ?? + SportDetails.football, ); String get location => GoRouteData.$location( '/enhanced-enum-route/${Uri.encodeComponent(_$SportDetailsEnumMap[requiredEnumField]!)}', queryParams: { if (enumField != null) - 'enum-field': _$SportDetailsEnumMap[enumField!]!, + 'enum-field': _$SportDetailsEnumMap[enumField!], + if (enumFieldWithDefaultValue != SportDetails.football) + 'enum-field-with-default-value': + _$SportDetailsEnumMap[enumFieldWithDefaultValue], }, ); void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $StringRouteExtension on StringRoute { static StringRoute _fromState(GoRouterState state) => StringRoute( requiredStringField: state.params['requiredStringField']!, stringField: state.queryParams['string-field'], + stringFieldWithDefaultValue: + state.queryParams['string-field-with-default-value'] ?? + 'defaultValue', ); String get location => GoRouteData.$location( '/string-route/${Uri.encodeComponent(requiredStringField)}', queryParams: { - if (stringField != null) 'string-field': stringField!, + if (stringField != null) 'string-field': stringField, + if (stringFieldWithDefaultValue != 'defaultValue') + 'string-field-with-default-value': stringFieldWithDefaultValue, }, ); void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $UriRouteExtension on UriRoute { @@ -266,6 +347,104 @@ extension $UriRouteExtension on UriRoute { void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); +} + +extension $IterableRouteExtension on IterableRoute { + static IterableRoute _fromState(GoRouterState state) => IterableRoute( + intIterableField: + state.queryParametersAll['int-iterable-field']?.map(int.parse), + doubleIterableField: state.queryParametersAll['double-iterable-field'] + ?.map(double.parse), + stringIterableField: + state.queryParametersAll['string-iterable-field']?.map((e) => e), + boolIterableField: state.queryParametersAll['bool-iterable-field'] + ?.map(_$boolConverter), + enumIterableField: state.queryParametersAll['enum-iterable-field'] + ?.map(_$SportDetailsEnumMap._$fromName), + intListField: + state.queryParametersAll['int-list-field']?.map(int.parse).toList(), + doubleListField: state.queryParametersAll['double-list-field'] + ?.map(double.parse) + .toList(), + stringListField: state.queryParametersAll['string-list-field'] + ?.map((e) => e) + .toList(), + boolListField: state.queryParametersAll['bool-list-field'] + ?.map(_$boolConverter) + .toList(), + enumListField: state.queryParametersAll['enum-list-field'] + ?.map(_$SportDetailsEnumMap._$fromName) + .toList(), + intSetField: + state.queryParametersAll['int-set-field']?.map(int.parse).toSet(), + doubleSetField: state.queryParametersAll['double-set-field'] + ?.map(double.parse) + .toSet(), + stringSetField: + state.queryParametersAll['string-set-field']?.map((e) => e).toSet(), + boolSetField: state.queryParametersAll['bool-set-field'] + ?.map(_$boolConverter) + .toSet(), + enumSetField: state.queryParametersAll['enum-set-field'] + ?.map(_$SportDetailsEnumMap._$fromName) + .toSet(), + ); + + String get location => GoRouteData.$location( + '/iterable-route', + queryParams: { + if (intIterableField != null) + 'int-iterable-field': + intIterableField?.map((e) => e.toString()).toList(), + if (doubleIterableField != null) + 'double-iterable-field': + doubleIterableField?.map((e) => e.toString()).toList(), + if (stringIterableField != null) + 'string-iterable-field': + stringIterableField?.map((e) => e).toList(), + if (boolIterableField != null) + 'bool-iterable-field': + boolIterableField?.map((e) => e.toString()).toList(), + if (enumIterableField != null) + 'enum-iterable-field': enumIterableField + ?.map((e) => _$SportDetailsEnumMap[e]) + .toList(), + if (intListField != null) + 'int-list-field': intListField?.map((e) => e.toString()).toList(), + if (doubleListField != null) + 'double-list-field': + doubleListField?.map((e) => e.toString()).toList(), + if (stringListField != null) + 'string-list-field': stringListField?.map((e) => e).toList(), + if (boolListField != null) + 'bool-list-field': boolListField?.map((e) => e.toString()).toList(), + if (enumListField != null) + 'enum-list-field': + enumListField?.map((e) => _$SportDetailsEnumMap[e]).toList(), + if (intSetField != null) + 'int-set-field': intSetField?.map((e) => e.toString()).toList(), + if (doubleSetField != null) + 'double-set-field': + doubleSetField?.map((e) => e.toString()).toList(), + if (stringSetField != null) + 'string-set-field': stringSetField?.map((e) => e).toList(), + if (boolSetField != null) + 'bool-set-field': boolSetField?.map((e) => e.toString()).toList(), + if (enumSetField != null) + 'enum-set-field': + enumSetField?.map((e) => _$SportDetailsEnumMap[e]).toList(), + }, + ); + + void go(BuildContext context) => context.go(location); + + void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } const _$PersonDetailsEnumMap = { diff --git a/packages/go_router_builder/example/lib/main.g.dart b/packages/go_router_builder/example/lib/main.g.dart index b909df66db79..ff7a23627c97 100644 --- a/packages/go_router_builder/example/lib/main.g.dart +++ b/packages/go_router_builder/example/lib/main.g.dart @@ -46,6 +46,9 @@ extension $HomeRouteExtension on HomeRoute { void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $FamilyRouteExtension on FamilyRoute { @@ -60,6 +63,9 @@ extension $FamilyRouteExtension on FamilyRoute { void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $PersonRouteExtension on PersonRoute { @@ -75,6 +81,9 @@ extension $PersonRouteExtension on PersonRoute { void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $PersonDetailsRouteExtension on PersonDetailsRoute { @@ -93,6 +102,9 @@ extension $PersonDetailsRouteExtension on PersonDetailsRoute { void go(BuildContext context) => context.go(location, extra: $extra); void push(BuildContext context) => context.push(location, extra: $extra); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location, extra: $extra); } const _$PersonDetailsEnumMap = { @@ -119,11 +131,14 @@ extension $LoginRouteExtension on LoginRoute { String get location => GoRouteData.$location( '/login', queryParams: { - if (fromPage != null) 'from-page': fromPage!, + if (fromPage != null) 'from-page': fromPage, }, ); void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } diff --git a/packages/go_router_builder/example/lib/simple_example.g.dart b/packages/go_router_builder/example/lib/simple_example.g.dart index 58e229a28171..6f9eb6a5eef1 100644 --- a/packages/go_router_builder/example/lib/simple_example.g.dart +++ b/packages/go_router_builder/example/lib/simple_example.g.dart @@ -33,6 +33,9 @@ extension $HomeRouteExtension on HomeRoute { void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } extension $FamilyRouteExtension on FamilyRoute { @@ -47,4 +50,7 @@ extension $FamilyRouteExtension on FamilyRoute { void go(BuildContext context) => context.go(location); void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); } diff --git a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart index e5e008dfce90..6daa572d50e6 100644 --- a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart +++ b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart @@ -120,53 +120,47 @@ enum EnumTest { final int x; } - @ShouldGenerate(r''' -GoRoute get $enumParam => GoRouteData.$route( - path: '/:y', - factory: $EnumParamExtension._fromState, +GoRoute get $defaultValueRoute => GoRouteData.$route( + path: '/default-value-route', + factory: $DefaultValueRouteExtension._fromState, ); -extension $EnumParamExtension on EnumParam { - static EnumParam _fromState(GoRouterState state) => EnumParam( - y: _$EnumTestEnumMap._$fromName(state.params['y']!), +extension $DefaultValueRouteExtension on DefaultValueRoute { + static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute( + param: _$convertMapValue('param', state.queryParams, int.parse) ?? 0, ); String get location => GoRouteData.$location( - '/${Uri.encodeComponent(_$EnumTestEnumMap[y]!)}', + '/default-value-route', + queryParams: { + if (param != 0) 'param': param.toString(), + }, ); - void go(BuildContext context) => context.go(location); + void go(BuildContext context) => context.go(location, extra: this); - void push(BuildContext context) => context.push(location); -} + void push(BuildContext context) => context.push(location, extra: this); -const _$EnumTestEnumMap = { - EnumTest.a: 'a', - EnumTest.b: 'b', - EnumTest.c: 'c', -}; + void pushReplacement(BuildContext context) => + context.pushReplacement(location, extra: this); +} -extension on Map { - T _$fromName(String value) => - entries.singleWhere((element) => element.value == value).key; +T? _$convertMapValue( + String key, + Map map, + T Function(String) converter, +) { + final value = map[key]; + return value == null ? null : converter(value); } ''') -@TypedGoRoute(path: '/:y') -class EnumParamWithExtra extends GoRouteData { - EnumParamWithExtra({required this.y, this.$extra}); - final EnumWithExtraTest y; - final int? $extra; +@TypedGoRoute(path: '/default-value-route') +class DefaultValueRoute extends GoRouteData { + DefaultValueRoute({this.param = 0}); + final int param; } -enum EnumWithExtraTest { - a(1), - b(3), - c(5); - - const EnumWithExtraTest(this.x); - final int x; - @ShouldGenerate(r''' GoRoute get $defaultValueRoute => GoRouteData.$route( @@ -204,8 +198,8 @@ T? _$convertMapValue( } ''') @TypedGoRoute(path: '/default-value-route') -class DefaultValueRoute extends GoRouteData { - DefaultValueRoute({this.param = 0}); +class ExtraValueRoute extends GoRouteData { + ExtraValueRoute({this.param = 0}); final int param; } From d9b476fade49d7efde83995d420cd390a2062f3f Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Sat, 25 Feb 2023 18:26:07 -0800 Subject: [PATCH 07/11] lint --- packages/go_router_builder/lib/src/route_config.dart | 3 ++- .../test/test_inputs/_go_router_builder_test_input.dart | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index d3c3f0e86f63..87087a368fe1 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -189,8 +189,9 @@ GoRoute get $_routeGetterName => ${_routeDefinition()}; yield _enumMapConst(enumParamType); } } + ParameterElement? get _extraParam => _ctor.parameters - .singleWhereOrNull((ParameterElement element) => element.isExtraField); + .singleWhereOrNull((ParameterElement element) => element.isExtraField); String get _newFromState { final StringBuffer buffer = StringBuffer('=>'); diff --git a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart index 6daa572d50e6..183f045a0efd 100644 --- a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart +++ b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart @@ -161,7 +161,6 @@ class DefaultValueRoute extends GoRouteData { final int param; } - @ShouldGenerate(r''' GoRoute get $defaultValueRoute => GoRouteData.$route( path: '/default-value-route', From d3328064d42960199ac297cc9a46f92e682dd150 Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Sat, 25 Feb 2023 18:28:38 -0800 Subject: [PATCH 08/11] Update _go_router_builder_test_input.dart --- .../test_inputs/_go_router_builder_test_input.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart index 183f045a0efd..8f4dba2068d8 100644 --- a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart +++ b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart @@ -162,13 +162,13 @@ class DefaultValueRoute extends GoRouteData { } @ShouldGenerate(r''' -GoRoute get $defaultValueRoute => GoRouteData.$route( +GoRoute get $extraValueRoute => GoRouteData.$route( path: '/default-value-route', - factory: $DefaultValueRouteExtension._fromState, + factory: $ExtraValueRouteExtension._fromState, ); -extension $DefaultValueRouteExtension on DefaultValueRoute { - static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute( +extension $ExtraValueRouteExtension on ExtraValueRoute { + static ExtraValueRoute _fromState(GoRouterState state) => ExtraValueRoute( param: _$convertMapValue('param', state.queryParams, int.parse) ?? 0, ); @@ -196,10 +196,11 @@ T? _$convertMapValue( return value == null ? null : converter(value); } ''') -@TypedGoRoute(path: '/default-value-route') +@TypedGoRoute(path: '/default-value-route') class ExtraValueRoute extends GoRouteData { - ExtraValueRoute({this.param = 0}); + ExtraValueRoute({this.param = 0, this.$extra}); final int param; + final int? $extra; } @ShouldThrow( From 16b632187f4bbfa01a63d7acbfc8b2acc62fcf11 Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Sat, 25 Feb 2023 18:35:23 -0800 Subject: [PATCH 09/11] test --- packages/go_router_builder/test/builder_test.dart | 1 + .../test_inputs/_go_router_builder_test_input.dart | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/go_router_builder/test/builder_test.dart b/packages/go_router_builder/test/builder_test.dart index 644c13f70b34..68c5a1b28aeb 100644 --- a/packages/go_router_builder/test/builder_test.dart +++ b/packages/go_router_builder/test/builder_test.dart @@ -25,6 +25,7 @@ const Set _expectedAnnotatedTests = { 'AppliedToWrongClassType', 'BadPathParam', 'ExtraMustBeOptional', + 'ExtraValueRoute', 'MissingPathParam', 'MissingPathValue', 'MissingTypeAnnotation', diff --git a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart index 8f4dba2068d8..3d1c6b21f0bd 100644 --- a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart +++ b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart @@ -138,12 +138,12 @@ extension $DefaultValueRouteExtension on DefaultValueRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context) => context.go(location); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context) => context.push(location); void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: this); + context.pushReplacement(location); } T? _$convertMapValue( @@ -179,12 +179,12 @@ extension $ExtraValueRouteExtension on ExtraValueRoute { }, ); - void go(BuildContext context) => context.go(location, extra: this); + void go(BuildContext context) => context.go(location, extra: $extra); - void push(BuildContext context) => context.push(location, extra: this); + void push(BuildContext context) => context.push(location, extra: $extra); void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: this); + context.pushReplacement(location, extra: $extra); } T? _$convertMapValue( From 2a9c5b24a161fae801f8280656f45b33161895c3 Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Sat, 25 Feb 2023 18:39:26 -0800 Subject: [PATCH 10/11] Update _go_router_builder_test_input.dart --- .../test/test_inputs/_go_router_builder_test_input.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart index 3d1c6b21f0bd..abb47ad5b7d8 100644 --- a/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart +++ b/packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart @@ -170,6 +170,7 @@ GoRoute get $extraValueRoute => GoRouteData.$route( extension $ExtraValueRouteExtension on ExtraValueRoute { static ExtraValueRoute _fromState(GoRouterState state) => ExtraValueRoute( param: _$convertMapValue('param', state.queryParams, int.parse) ?? 0, + $extra: state.extra as int?, ); String get location => GoRouteData.$location( From b029c2759951b6972be02884d9883b460d012774 Mon Sep 17 00:00:00 2001 From: hangyu <108393416+hangyujin@users.noreply.github.com> Date: Sat, 25 Feb 2023 18:45:11 -0800 Subject: [PATCH 11/11] Update pubspec.yaml --- packages/go_router_builder/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 1eead91f4cd8..a5fb5ae30f97 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -2,7 +2,7 @@ name: go_router_builder description: >- A builder that supports generated strongly-typed route helpers for package:go_router -version: 1.1.2 +version: 1.1.3 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