From ded3b07dbe1c760cdbd3897b74b4310429ac629b Mon Sep 17 00:00:00 2001 From: Daniele Cambi Date: Sat, 8 Apr 2023 15:38:39 +0200 Subject: [PATCH 01/13] adds name parameter to TypedGoRoute --- packages/go_router/lib/src/route_data.dart | 8 ++++++++ .../go_router_builder/example/lib/all_types.g.dart | 14 ++++++++++++++ packages/go_router_builder/example/lib/main.g.dart | 5 +++++ .../example/lib/simple_example.dart | 1 + .../example/lib/simple_example.g.dart | 2 ++ .../go_router_builder/lib/src/route_config.dart | 8 +++++++- 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/go_router/lib/src/route_data.dart b/packages/go_router/lib/src/route_data.dart index 2be9c36478b7..d0c9e250817b 100644 --- a/packages/go_router/lib/src/route_data.dart +++ b/packages/go_router/lib/src/route_data.dart @@ -223,6 +223,7 @@ class TypedGoRoute extends TypedRoute { /// Default const constructor const TypedGoRoute({ required this.path, + this.name, this.routes = const >[], this.parentNavigatorKey, }); @@ -234,6 +235,13 @@ class TypedGoRoute extends TypedRoute { /// final String path; + /// The name that corresponds to this route. + /// + /// See [GoRoute.name]. + /// + /// + final String? name; + /// Child route definitions. /// /// See [RouteBase.routes]. 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 f38dadc20217..237de2afb613 100644 --- a/packages/go_router_builder/example/lib/all_types.g.dart +++ b/packages/go_router_builder/example/lib/all_types.g.dart @@ -14,58 +14,72 @@ List get $appRoutes => [ GoRoute get $allTypesBaseRoute => GoRouteData.$route( path: '/', + name: null, factory: $AllTypesBaseRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'big-int-route/:requiredBigIntField', + name: null, factory: $BigIntRouteExtension._fromState, ), GoRouteData.$route( path: 'bool-route/:requiredBoolField', + name: null, factory: $BoolRouteExtension._fromState, ), GoRouteData.$route( path: 'date-time-route/:requiredDateTimeField', + name: null, factory: $DateTimeRouteExtension._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', + name: null, factory: $DoubleRouteExtension._fromState, ), GoRouteData.$route( path: 'int-route/:requiredIntField', + name: null, factory: $IntRouteExtension._fromState, ), GoRouteData.$route( path: 'num-route/:requiredNumField', + name: null, factory: $NumRouteExtension._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', + name: null, factory: $DoubleRouteExtension._fromState, ), GoRouteData.$route( path: 'enum-route/:requiredEnumField', + name: null, factory: $EnumRouteExtension._fromState, ), GoRouteData.$route( path: 'enhanced-enum-route/:requiredEnumField', + name: null, factory: $EnhancedEnumRouteExtension._fromState, ), GoRouteData.$route( path: 'string-route/:requiredStringField', + name: null, factory: $StringRouteExtension._fromState, ), GoRouteData.$route( path: 'uri-route/:requiredUriField', + name: null, factory: $UriRouteExtension._fromState, ), GoRouteData.$route( path: 'iterable-route', + name: null, factory: $IterableRouteExtension._fromState, ), GoRouteData.$route( path: 'iterable-route-with-default-values', + name: null, factory: $IterableRouteWithDefaultValuesExtension._fromState, ), ], diff --git a/packages/go_router_builder/example/lib/main.g.dart b/packages/go_router_builder/example/lib/main.g.dart index ff7a23627c97..965e91d7b8fb 100644 --- a/packages/go_router_builder/example/lib/main.g.dart +++ b/packages/go_router_builder/example/lib/main.g.dart @@ -15,18 +15,22 @@ List get $appRoutes => [ GoRoute get $homeRoute => GoRouteData.$route( path: '/', + name: null, factory: $HomeRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'family/:fid', + name: null, factory: $FamilyRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'person/:pid', + name: null, factory: $PersonRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'details/:details', + name: null, factory: $PersonDetailsRouteExtension._fromState, ), ], @@ -120,6 +124,7 @@ extension on Map { GoRoute get $loginRoute => GoRouteData.$route( path: '/login', + name: null, factory: $LoginRouteExtension._fromState, ); diff --git a/packages/go_router_builder/example/lib/simple_example.dart b/packages/go_router_builder/example/lib/simple_example.dart index 6253fc6e9d16..dee29d0c867c 100644 --- a/packages/go_router_builder/example/lib/simple_example.dart +++ b/packages/go_router_builder/example/lib/simple_example.dart @@ -28,6 +28,7 @@ class App extends StatelessWidget { @TypedGoRoute( path: '/', + name: 'Home', routes: >[ TypedGoRoute(path: 'family/:familyId') ], 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 6f9eb6a5eef1..526625909800 100644 --- a/packages/go_router_builder/example/lib/simple_example.g.dart +++ b/packages/go_router_builder/example/lib/simple_example.g.dart @@ -14,10 +14,12 @@ List get $appRoutes => [ GoRoute get $homeRoute => GoRouteData.$route( path: '/', + name: 'Home', factory: $HomeRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'family/:familyId', + name: null, factory: $FamilyRouteExtension._fromState, ), ], diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index cfc4863fedfa..71867205ecf1 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -37,6 +37,7 @@ class InfoIterable extends IterableBase { class RouteConfig { RouteConfig._( this._path, + this._name, this._routeDataClass, this._parent, ); @@ -74,7 +75,10 @@ class RouteConfig { ); } + final ConstantReader nameValue = reader.read('name'); + final String path = pathValue.stringValue; + final String? name = nameValue.isNull ? null : nameValue.stringValue; final InterfaceType type = reader.objectValue.type! as InterfaceType; final DartType typeParamType = type.typeArguments.single; @@ -93,7 +97,7 @@ class RouteConfig { // ignore: deprecated_member_use final InterfaceElement classElement = typeParamType.element; - final RouteConfig value = RouteConfig._(path, classElement, parent); + final RouteConfig value = RouteConfig._(path, name, classElement, parent); value._children.addAll(reader.read('routes').listValue.map((DartObject e) => RouteConfig._fromAnnotation(ConstantReader(e), element, value))); @@ -103,6 +107,7 @@ class RouteConfig { final List _children = []; final String _path; + final String? _name; final InterfaceElement _routeDataClass; final RouteConfig? _parent; @@ -275,6 +280,7 @@ routes: [${_children.map((RouteConfig e) => '${e._routeDefinition()},').join()}] return ''' GoRouteData.\$route( path: ${escapeDartString(_path)}, + name: ${_name == null ? null : escapeDartString(_name!)}, factory: $_extensionName._fromState, $routesBit ) From 5f467ceb539b7c1341b36dd7fbe5f4ab6d457618 Mon Sep 17 00:00:00 2001 From: Daniele Cambi Date: Sat, 8 Apr 2023 16:12:36 +0200 Subject: [PATCH 02/13] adds tests --- .../lib/src/route_config.dart | 2 +- .../go_router_builder/test/builder_test.dart | 1 + .../_go_router_builder_test_input.dart | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index 71867205ecf1..be250a01b8fe 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -280,7 +280,7 @@ routes: [${_children.map((RouteConfig e) => '${e._routeDefinition()},').join()}] return ''' GoRouteData.\$route( path: ${escapeDartString(_path)}, - name: ${_name == null ? null : escapeDartString(_name!)}, + ${_name != null ? 'name: ${escapeDartString(_name!)},' : ''} factory: $_extensionName._fromState, $routesBit ) diff --git a/packages/go_router_builder/test/builder_test.dart b/packages/go_router_builder/test/builder_test.dart index 348687f2b76b..015d721ea7d6 100644 --- a/packages/go_router_builder/test/builder_test.dart +++ b/packages/go_router_builder/test/builder_test.dart @@ -37,4 +37,5 @@ const Set _expectedAnnotatedTests = { 'NullableDefaultValueRoute', 'IterableWithEnumRoute', 'IterableDefaultValueRoute', + 'NamedRoute', }; 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 9875d2e921ee..5976d1f6066d 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 @@ -302,3 +302,28 @@ class IterableDefaultValueRoute extends GoRouteData { IterableDefaultValueRoute({this.param = const [0]}); final Iterable param; } + +@ShouldGenerate(r''' +GoRoute get $namedRoute => GoRouteData.$route( + path: '/named-route', + name: 'namedRoute', + factory: $NamedRouteExtension._fromState, + ); + +extension $NamedRouteExtension on NamedRoute { + static NamedRoute _fromState(GoRouterState state) => NamedRoute(); + + String get location => GoRouteData.$location( + '/named-route', + ); + + void go(BuildContext context) => context.go(location); + + void push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); +} +''') +@TypedGoRoute(path: '/named-route', name: 'namedRoute') +class NamedRoute extends GoRouteData {} From 8592c5eb13d1c4adafbbf13a9f78f4ac41d170da Mon Sep 17 00:00:00 2001 From: Daniele Cambi Date: Sat, 8 Apr 2023 16:31:35 +0200 Subject: [PATCH 03/13] updates changelog and pubspec --- packages/go_router/CHANGELOG.md | 4 ++++ packages/go_router/pubspec.yaml | 2 +- packages/go_router_builder/CHANGELOG.md | 4 ++++ packages/go_router_builder/pubspec.yaml | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index 4a72e8a35008..8370aed65def 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.5.3 + +- Adds name parameter to `TypedGoRoute` + ## 6.5.2 - NoTransitionPage now has an instant reverse transition diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 873ed655dacb..b9e11e10cc9d 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -1,7 +1,7 @@ name: go_router description: A declarative router for Flutter based on Navigation 2 supporting deep linking, data-driven routes and more -version: 6.5.2 +version: 6.5.3 repository: https://github.com/flutter/packages/tree/main/packages/go_router issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22 diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index b1f15fba7d31..471ca4700445 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.8 + +* Supports name parameter for `TypedGoRoute`. + ## 1.1.7 * Supports default values for `Set`, `List` and `Iterable` route parameters. diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 5bc629aa3931..18561fde3e27 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.7 +version: 1.1.8 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 From c5a5a404864c0aaf3eca20688d96eac12cb9800e Mon Sep 17 00:00:00 2001 From: Daniele Cambi Date: Sat, 8 Apr 2023 16:32:43 +0200 Subject: [PATCH 04/13] uses local go_router --- packages/go_router_builder/pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 18561fde3e27..797666852e1b 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 - go_router: ^5.0.0 + go_router: + path: ../go_router source_gen_test: ^1.0.0 test: ^1.20.0 From 637b37fcb1dd6f35c03e9ec6c2934d72dcfc1078 Mon Sep 17 00:00:00 2001 From: Daniele Cambi <43640732+dancamdev@users.noreply.github.com> Date: Thu, 13 Apr 2023 17:32:08 +0200 Subject: [PATCH 05/13] Update CHANGELOG.md --- packages/go_router/CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index a2feb39754ce..48ea89e41a6a 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,7 +1,3 @@ -## 6.5.6 - -- Adds name parameter to `TypedGoRoute` - ## 6.5.5 - Fixes an issue when popping pageless route would accidentally complete imperative page. From 94c5f3ec95409fb2248d633e7c7d2a6871bb1c28 Mon Sep 17 00:00:00 2001 From: Daniele Cambi <43640732+dancamdev@users.noreply.github.com> Date: Thu, 13 Apr 2023 17:32:50 +0200 Subject: [PATCH 06/13] Update route_data.dart --- packages/go_router/lib/src/route_data.dart | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/go_router/lib/src/route_data.dart b/packages/go_router/lib/src/route_data.dart index ab362749c431..3530ca250fc4 100644 --- a/packages/go_router/lib/src/route_data.dart +++ b/packages/go_router/lib/src/route_data.dart @@ -223,7 +223,6 @@ class TypedGoRoute extends TypedRoute { /// Default const constructor const TypedGoRoute({ required this.path, - this.name, this.routes = const >[], }); @@ -234,13 +233,6 @@ class TypedGoRoute extends TypedRoute { /// final String path; - /// The name that corresponds to this route. - /// - /// See [GoRoute.name]. - /// - /// - final String? name; - /// Child route definitions. /// /// See [RouteBase.routes]. From 6ddd3c3ecca3c91406ba37f8b18b705fd3273089 Mon Sep 17 00:00:00 2001 From: Daniele Cambi <43640732+dancamdev@users.noreply.github.com> Date: Thu, 13 Apr 2023 17:33:14 +0200 Subject: [PATCH 07/13] Update pubspec.yaml --- packages/go_router/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 5c08a6a13c89..5dbf1d9bdd51 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -1,7 +1,7 @@ name: go_router description: A declarative router for Flutter based on Navigation 2 supporting deep linking, data-driven routes and more -version: 6.5.6 +version: 6.5.5 repository: https://github.com/flutter/packages/tree/main/packages/go_router issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22 From c2df8aacd941c179f92161acd47181c6fa16a68d Mon Sep 17 00:00:00 2001 From: MicheleBenedetti <45004856+Michele-x98@users.noreply.github.com> Date: Thu, 27 Apr 2023 19:26:06 +0200 Subject: [PATCH 08/13] fix go_router version from local to remote --- packages/go_router_builder/example/pubspec.yaml | 2 +- packages/go_router_builder/pubspec.yaml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/go_router_builder/example/pubspec.yaml b/packages/go_router_builder/example/pubspec.yaml index b8b7c9fa6798..3375b124d91b 100644 --- a/packages/go_router_builder/example/pubspec.yaml +++ b/packages/go_router_builder/example/pubspec.yaml @@ -8,7 +8,7 @@ environment: dependencies: flutter: sdk: flutter - go_router: ^6.2.0 + go_router: ^6.5.8 provider: 6.0.5 dev_dependencies: diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 3739ebb795ed..37c8094ba7ea 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -23,7 +23,6 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 - go_router: - path: ../go_router + go_router: ^6.5.8 source_gen_test: ^1.0.0 test: ^1.20.0 From 49668c2115d3b609803bb5a631ce644845c3faab Mon Sep 17 00:00:00 2001 From: MicheleBenedetti <45004856+Michele-x98@users.noreply.github.com> Date: Thu, 27 Apr 2023 19:43:36 +0200 Subject: [PATCH 09/13] fix tests with return value from push method --- .../test/test_inputs/_go_router_builder_test_input.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 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 c46b8bb2747c..164f34244a0d 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 @@ -327,7 +327,7 @@ class IterableDefaultValueRoute extends GoRouteData { } @ShouldGenerate(r''' -GoRoute get $namedRoute => GoRouteData.$route( +RouteBase get $namedRoute => GoRouteData.$route( path: '/named-route', name: 'namedRoute', factory: $NamedRouteExtension._fromState, @@ -342,7 +342,7 @@ extension $NamedRouteExtension on NamedRoute { void go(BuildContext context) => context.go(location); - void push(BuildContext context) => context.push(location); + Future push(BuildContext context) => context.push(location); void pushReplacement(BuildContext context) => context.pushReplacement(location); From c034451935643d156327bdf02178da68b5720989 Mon Sep 17 00:00:00 2001 From: MicheleBenedetti <45004856+Michele-x98@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:17:41 +0200 Subject: [PATCH 10/13] fix version --- 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 37c8094ba7ea..c77c7400e076 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.2.2 +version: 1.2.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 From ec70a3e8dcd3a48f852befff383bcd58595551be Mon Sep 17 00:00:00 2001 From: Daniele Cambi Date: Fri, 28 Apr 2023 16:01:08 +0200 Subject: [PATCH 11/13] fixes build_runner error Co-authored-by: MicheleBenedetti --- .../go_router_builder/example/lib/all_types.g.dart | 14 -------------- packages/go_router_builder/example/lib/main.g.dart | 5 ----- .../example/lib/simple_example.g.dart | 1 - .../go_router_builder/lib/src/route_config.dart | 7 ++++--- 4 files changed, 4 insertions(+), 23 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 4d5a416bb5d5..7cf692f6cbe7 100644 --- a/packages/go_router_builder/example/lib/all_types.g.dart +++ b/packages/go_router_builder/example/lib/all_types.g.dart @@ -14,72 +14,58 @@ List get $appRoutes => [ RouteBase get $allTypesBaseRoute => GoRouteData.$route( path: '/', - name: null, factory: $AllTypesBaseRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'big-int-route/:requiredBigIntField', - name: null, factory: $BigIntRouteExtension._fromState, ), GoRouteData.$route( path: 'bool-route/:requiredBoolField', - name: null, factory: $BoolRouteExtension._fromState, ), GoRouteData.$route( path: 'date-time-route/:requiredDateTimeField', - name: null, factory: $DateTimeRouteExtension._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', - name: null, factory: $DoubleRouteExtension._fromState, ), GoRouteData.$route( path: 'int-route/:requiredIntField', - name: null, factory: $IntRouteExtension._fromState, ), GoRouteData.$route( path: 'num-route/:requiredNumField', - name: null, factory: $NumRouteExtension._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', - name: null, factory: $DoubleRouteExtension._fromState, ), GoRouteData.$route( path: 'enum-route/:requiredEnumField', - name: null, factory: $EnumRouteExtension._fromState, ), GoRouteData.$route( path: 'enhanced-enum-route/:requiredEnumField', - name: null, factory: $EnhancedEnumRouteExtension._fromState, ), GoRouteData.$route( path: 'string-route/:requiredStringField', - name: null, factory: $StringRouteExtension._fromState, ), GoRouteData.$route( path: 'uri-route/:requiredUriField', - name: null, factory: $UriRouteExtension._fromState, ), GoRouteData.$route( path: 'iterable-route', - name: null, factory: $IterableRouteExtension._fromState, ), GoRouteData.$route( path: 'iterable-route-with-default-values', - name: null, factory: $IterableRouteWithDefaultValuesExtension._fromState, ), ], diff --git a/packages/go_router_builder/example/lib/main.g.dart b/packages/go_router_builder/example/lib/main.g.dart index 2e1f73b29549..864e8e121ef8 100644 --- a/packages/go_router_builder/example/lib/main.g.dart +++ b/packages/go_router_builder/example/lib/main.g.dart @@ -15,22 +15,18 @@ List get $appRoutes => [ RouteBase get $homeRoute => GoRouteData.$route( path: '/', - name: null, factory: $HomeRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'family/:fid', - name: null, factory: $FamilyRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'person/:pid', - name: null, factory: $PersonRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'details/:details', - name: null, factory: $PersonDetailsRouteExtension._fromState, ), ], @@ -146,7 +142,6 @@ extension on Map { RouteBase get $loginRoute => GoRouteData.$route( path: '/login', - name: null, factory: $LoginRouteExtension._fromState, ); 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 e7016de7bc0b..fb61fa304b52 100644 --- a/packages/go_router_builder/example/lib/simple_example.g.dart +++ b/packages/go_router_builder/example/lib/simple_example.g.dart @@ -19,7 +19,6 @@ RouteBase get $homeRoute => GoRouteData.$route( routes: [ GoRouteData.$route( path: 'family/:familyId', - name: null, factory: $FamilyRouteExtension._fromState, ), ], diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index b2cbf816515a..a67f33bab059 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -76,6 +76,7 @@ class RouteConfig { final bool isShellRoute = type.element.name == 'TypedShellRoute'; String? path; + String? name; if (!isShellRoute) { final ConstantReader pathValue = reader.read('path'); @@ -86,10 +87,10 @@ class RouteConfig { ); } path = pathValue.stringValue; - } - final ConstantReader nameValue = reader.read('name'); - final String? name = nameValue.isNull ? null : nameValue.stringValue; + final ConstantReader nameValue = reader.read('name'); + name = nameValue.isNull ? null : nameValue.stringValue; + } final DartType typeParamType = type.typeArguments.single; if (typeParamType is! InterfaceType) { From 1ddc59c2b537bd2914f6cb54385fa395f7f03c9b Mon Sep 17 00:00:00 2001 From: Daniele Cambi <43640732+dancamdev@users.noreply.github.com> Date: Mon, 8 May 2023 11:22:40 +0200 Subject: [PATCH 12/13] adds NamedEscapeRoute test --- .../go_router_builder/test/builder_test.dart | 1 + .../_go_router_builder_test_input.dart | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/go_router_builder/test/builder_test.dart b/packages/go_router_builder/test/builder_test.dart index 442a870877b8..056d854a4c00 100644 --- a/packages/go_router_builder/test/builder_test.dart +++ b/packages/go_router_builder/test/builder_test.dart @@ -38,4 +38,5 @@ const Set _expectedAnnotatedTests = { 'IterableWithEnumRoute', 'IterableDefaultValueRoute', 'NamedRoute', + 'NamedEscapedRoute', }; 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 8e068e034544..31b009a68010 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 @@ -352,3 +352,29 @@ extension $NamedRouteExtension on NamedRoute { ''') @TypedGoRoute(path: '/named-route', name: 'namedRoute') class NamedRoute extends GoRouteData {} + +@ShouldGenerate(r''' +RouteBase get $namedEscapedRoute => GoRouteData.$route( + path: '/named-route', + name: r'named$Route', + factory: $NamedEscapedRouteExtension._fromState, + ); + +extension $NamedEscapedRouteExtension on NamedEscapedRoute { + static NamedEscapedRoute _fromState(GoRouterState state) => + NamedEscapedRoute(); + + String get location => GoRouteData.$location( + '/named-route', + ); + + void go(BuildContext context) => context.go(location); + + Future push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location); +} +''') +@TypedGoRoute(path: '/named-route', name: 'named\$Route') +class NamedEscapedRoute extends GoRouteData {} From 27da54a222df95ec7ed19393a275026332146d20 Mon Sep 17 00:00:00 2001 From: Daniele Cambi <43640732+dancamdev@users.noreply.github.com> Date: Mon, 8 May 2023 11:28:19 +0200 Subject: [PATCH 13/13] fixes lint errors --- .../test/test_inputs/_go_router_builder_test_input.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 31b009a68010..678a5286e088 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 @@ -376,5 +376,5 @@ extension $NamedEscapedRouteExtension on NamedEscapedRoute { context.pushReplacement(location); } ''') -@TypedGoRoute(path: '/named-route', name: 'named\$Route') +@TypedGoRoute(path: '/named-route', name: r'named$Route') class NamedEscapedRoute extends GoRouteData {}