diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index c204e83cbc3c..1c7b9366fb11 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.0 + +- Route classes now required to use a mixin `with _$RouteName`. + ## 2.9.1 - Fixes an deprecated warning for using withNullability diff --git a/packages/go_router_builder/README.md b/packages/go_router_builder/README.md index 5d90b22f2851..6472f56e1d50 100644 --- a/packages/go_router_builder/README.md +++ b/packages/go_router_builder/README.md @@ -86,7 +86,7 @@ method. ```dart -class HomeRoute extends GoRouteData { +class HomeRoute extends GoRouteData with _$HomeRoute { const HomeRoute(); @override @@ -108,7 +108,7 @@ The tree of routes is defined as an attribute on each of the top-level routes: ), ], ) -class HomeRoute extends GoRouteData { +class HomeRoute extends GoRouteData with _$HomeRoute { const HomeRoute(); @override @@ -124,7 +124,7 @@ class RedirectRoute extends GoRouteData { } @TypedGoRoute(path: '/login') -class LoginRoute extends GoRouteData { +class LoginRoute extends GoRouteData with _$LoginRoute { LoginRoute({this.from}); final String? from; @@ -211,7 +211,7 @@ Parameters (named or positional) not listed in the path of `TypedGoRoute` indica ```dart @TypedGoRoute(path: '/login') -class LoginRoute extends GoRouteData { +class LoginRoute extends GoRouteData with _$LoginRoute { LoginRoute({this.from}); final String? from; @@ -229,7 +229,7 @@ For query parameters with a **non-nullable** type, you can define a default valu ```dart @TypedGoRoute(path: '/my-route') -class MyRoute extends GoRouteData { +class MyRoute extends GoRouteData with _$MyRoute { MyRoute({this.queryParameter = 'defaultValue'}); final String queryParameter; @@ -250,7 +250,7 @@ parameter with the special name `$extra`: ```dart -class PersonRouteWithExtra extends GoRouteData { +class PersonRouteWithExtra extends GoRouteData with _$PersonRouteWithExtra { PersonRouteWithExtra(this.$extra); final Person? $extra; @@ -281,7 +281,8 @@ You can, of course, combine the use of path, query and $extra parameters: ```dart @TypedGoRoute(path: '/:ketchup') -class HotdogRouteWithEverything extends GoRouteData { +class HotdogRouteWithEverything extends GoRouteData + with _$HotdogRouteWithEverything { HotdogRouteWithEverything(this.ketchup, this.mustard, this.$extra); final bool ketchup; // A required path parameter. final String? mustard; // An optional query parameter. diff --git a/packages/go_router_builder/example/lib/all_types.dart b/packages/go_router_builder/example/lib/all_types.dart index 63d73caa4c0c..2394a5e3715a 100644 --- a/packages/go_router_builder/example/lib/all_types.dart +++ b/packages/go_router_builder/example/lib/all_types.dart @@ -29,7 +29,7 @@ part 'all_types.g.dart'; path: 'iterable-route-with-default-values'), ]) @immutable -class AllTypesBaseRoute extends GoRouteData { +class AllTypesBaseRoute extends GoRouteData with _$AllTypesBaseRoute { const AllTypesBaseRoute(); @override @@ -39,7 +39,7 @@ class AllTypesBaseRoute extends GoRouteData { ); } -class BigIntRoute extends GoRouteData { +class BigIntRoute extends GoRouteData with _$BigIntRoute { BigIntRoute({ required this.requiredBigIntField, this.bigIntField, @@ -62,7 +62,7 @@ class BigIntRoute extends GoRouteData { ); } -class BoolRoute extends GoRouteData { +class BoolRoute extends GoRouteData with _$BoolRoute { BoolRoute({ required this.requiredBoolField, this.boolField, @@ -88,7 +88,7 @@ class BoolRoute extends GoRouteData { ); } -class DateTimeRoute extends GoRouteData { +class DateTimeRoute extends GoRouteData with _$DateTimeRoute { DateTimeRoute({ required this.requiredDateTimeField, this.dateTimeField, @@ -111,7 +111,7 @@ class DateTimeRoute extends GoRouteData { ); } -class DoubleRoute extends GoRouteData { +class DoubleRoute extends GoRouteData with _$DoubleRoute { DoubleRoute({ required this.requiredDoubleField, this.doubleField, @@ -137,7 +137,7 @@ class DoubleRoute extends GoRouteData { ); } -class IntRoute extends GoRouteData { +class IntRoute extends GoRouteData with _$IntRoute { IntRoute({ required this.requiredIntField, this.intField, @@ -163,7 +163,7 @@ class IntRoute extends GoRouteData { ); } -class NumRoute extends GoRouteData { +class NumRoute extends GoRouteData with _$NumRoute { NumRoute({ required this.requiredNumField, this.numField, @@ -189,7 +189,7 @@ class NumRoute extends GoRouteData { ); } -class EnumRoute extends GoRouteData { +class EnumRoute extends GoRouteData with _$EnumRoute { EnumRoute({ required this.requiredEnumField, this.enumField, @@ -216,7 +216,7 @@ class EnumRoute extends GoRouteData { ); } -class EnhancedEnumRoute extends GoRouteData { +class EnhancedEnumRoute extends GoRouteData with _$EnhancedEnumRoute { EnhancedEnumRoute({ required this.requiredEnumField, this.enumField, @@ -243,7 +243,7 @@ class EnhancedEnumRoute extends GoRouteData { ); } -class StringRoute extends GoRouteData { +class StringRoute extends GoRouteData with _$StringRoute { StringRoute({ required this.requiredStringField, this.stringField, @@ -269,7 +269,7 @@ class StringRoute extends GoRouteData { ); } -class UriRoute extends GoRouteData { +class UriRoute extends GoRouteData with _$UriRoute { UriRoute({ required this.requiredUriField, this.uriField, @@ -292,7 +292,7 @@ class UriRoute extends GoRouteData { ); } -class IterableRoute extends GoRouteData { +class IterableRoute extends GoRouteData with _$IterableRoute { IterableRoute({ this.intIterableField, this.doubleIterableField, @@ -365,7 +365,8 @@ class IterableRoute extends GoRouteData { ); } -class IterableRouteWithDefaultValues extends GoRouteData { +class IterableRouteWithDefaultValues extends GoRouteData + with _$IterableRouteWithDefaultValues { const IterableRouteWithDefaultValues({ this.intIterableField = const [0], this.doubleIterableField = const [0, 1, 2], 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 581814d47c25..6af36b14ee65 100644 --- a/packages/go_router_builder/example/lib/all_types.g.dart +++ b/packages/go_router_builder/example/lib/all_types.g.dart @@ -14,82 +14,87 @@ List get $appRoutes => [ RouteBase get $allTypesBaseRoute => GoRouteData.$route( path: '/', - factory: $AllTypesBaseRouteExtension._fromState, + factory: _$AllTypesBaseRoute._fromState, routes: [ GoRouteData.$route( path: 'big-int-route/:requiredBigIntField', - factory: $BigIntRouteExtension._fromState, + factory: _$BigIntRoute._fromState, ), GoRouteData.$route( path: 'bool-route/:requiredBoolField', - factory: $BoolRouteExtension._fromState, + factory: _$BoolRoute._fromState, ), GoRouteData.$route( path: 'date-time-route/:requiredDateTimeField', - factory: $DateTimeRouteExtension._fromState, + factory: _$DateTimeRoute._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', - factory: $DoubleRouteExtension._fromState, + factory: _$DoubleRoute._fromState, ), GoRouteData.$route( path: 'int-route/:requiredIntField', - factory: $IntRouteExtension._fromState, + factory: _$IntRoute._fromState, ), GoRouteData.$route( path: 'num-route/:requiredNumField', - factory: $NumRouteExtension._fromState, + factory: _$NumRoute._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', - factory: $DoubleRouteExtension._fromState, + factory: _$DoubleRoute._fromState, ), GoRouteData.$route( path: 'enum-route/:requiredEnumField', - factory: $EnumRouteExtension._fromState, + factory: _$EnumRoute._fromState, ), GoRouteData.$route( path: 'enhanced-enum-route/:requiredEnumField', - factory: $EnhancedEnumRouteExtension._fromState, + factory: _$EnhancedEnumRoute._fromState, ), GoRouteData.$route( path: 'string-route/:requiredStringField', - factory: $StringRouteExtension._fromState, + factory: _$StringRoute._fromState, ), GoRouteData.$route( path: 'uri-route/:requiredUriField', - factory: $UriRouteExtension._fromState, + factory: _$UriRoute._fromState, ), GoRouteData.$route( path: 'iterable-route', - factory: $IterableRouteExtension._fromState, + factory: _$IterableRoute._fromState, ), GoRouteData.$route( path: 'iterable-route-with-default-values', - factory: $IterableRouteWithDefaultValuesExtension._fromState, + factory: _$IterableRouteWithDefaultValues._fromState, ), ], ); -extension $AllTypesBaseRouteExtension on AllTypesBaseRoute { +mixin _$AllTypesBaseRoute on GoRouteData { static AllTypesBaseRoute _fromState(GoRouterState state) => const AllTypesBaseRoute(); + @override String get location => GoRouteData.$location( '/', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $BigIntRouteExtension on BigIntRoute { +mixin _$BigIntRoute on GoRouteData { static BigIntRoute _fromState(GoRouterState state) => BigIntRoute( requiredBigIntField: BigInt.parse(state.pathParameters['requiredBigIntField']!)!, @@ -97,24 +102,32 @@ extension $BigIntRouteExtension on BigIntRoute { 'big-int-field', state.uri.queryParameters, BigInt.tryParse), ); + BigIntRoute get _self => this as BigIntRoute; + + @override String get location => GoRouteData.$location( - '/big-int-route/${Uri.encodeComponent(requiredBigIntField.toString())}', + '/big-int-route/${Uri.encodeComponent(_self.requiredBigIntField.toString())}', queryParams: { - if (bigIntField != null) 'big-int-field': bigIntField!.toString(), + if (_self.bigIntField != null) + 'big-int-field': _self.bigIntField!.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $BoolRouteExtension on BoolRoute { +mixin _$BoolRoute on GoRouteData { static BoolRoute _fromState(GoRouterState state) => BoolRoute( requiredBoolField: _$boolConverter(state.pathParameters['requiredBoolField']!)!, @@ -127,27 +140,35 @@ extension $BoolRouteExtension on BoolRoute { true, ); + BoolRoute get _self => this as BoolRoute; + + @override String get location => GoRouteData.$location( - '/bool-route/${Uri.encodeComponent(requiredBoolField.toString())}', + '/bool-route/${Uri.encodeComponent(_self.requiredBoolField.toString())}', queryParams: { - if (boolField != null) 'bool-field': boolField!.toString(), - if (boolFieldWithDefaultValue != true) + if (_self.boolField != null) + 'bool-field': _self.boolField!.toString(), + if (_self.boolFieldWithDefaultValue != true) 'bool-field-with-default-value': - boolFieldWithDefaultValue.toString(), + _self.boolFieldWithDefaultValue.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $DateTimeRouteExtension on DateTimeRoute { +mixin _$DateTimeRoute on GoRouteData { static DateTimeRoute _fromState(GoRouterState state) => DateTimeRoute( requiredDateTimeField: DateTime.parse(state.pathParameters['requiredDateTimeField']!)!, @@ -155,25 +176,32 @@ extension $DateTimeRouteExtension on DateTimeRoute { 'date-time-field', state.uri.queryParameters, DateTime.tryParse), ); + DateTimeRoute get _self => this as DateTimeRoute; + + @override String get location => GoRouteData.$location( - '/date-time-route/${Uri.encodeComponent(requiredDateTimeField.toString())}', + '/date-time-route/${Uri.encodeComponent(_self.requiredDateTimeField.toString())}', queryParams: { - if (dateTimeField != null) - 'date-time-field': dateTimeField!.toString(), + if (_self.dateTimeField != null) + 'date-time-field': _self.dateTimeField!.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $DoubleRouteExtension on DoubleRoute { +mixin _$DoubleRoute on GoRouteData { static DoubleRoute _fromState(GoRouterState state) => DoubleRoute( requiredDoubleField: double.parse(state.pathParameters['requiredDoubleField']!)!, @@ -186,27 +214,35 @@ extension $DoubleRouteExtension on DoubleRoute { 1.0, ); + DoubleRoute get _self => this as DoubleRoute; + + @override String get location => GoRouteData.$location( - '/double-route/${Uri.encodeComponent(requiredDoubleField.toString())}', + '/double-route/${Uri.encodeComponent(_self.requiredDoubleField.toString())}', queryParams: { - if (doubleField != null) 'double-field': doubleField!.toString(), - if (doubleFieldWithDefaultValue != 1.0) + if (_self.doubleField != null) + 'double-field': _self.doubleField!.toString(), + if (_self.doubleFieldWithDefaultValue != 1.0) 'double-field-with-default-value': - doubleFieldWithDefaultValue.toString(), + _self.doubleFieldWithDefaultValue.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $IntRouteExtension on IntRoute { +mixin _$IntRoute on GoRouteData { static IntRoute _fromState(GoRouterState state) => IntRoute( requiredIntField: int.parse(state.pathParameters['requiredIntField']!)!, intField: _$convertMapValue( @@ -218,26 +254,34 @@ extension $IntRouteExtension on IntRoute { 1, ); + IntRoute get _self => this as IntRoute; + + @override String get location => GoRouteData.$location( - '/int-route/${Uri.encodeComponent(requiredIntField.toString())}', + '/int-route/${Uri.encodeComponent(_self.requiredIntField.toString())}', queryParams: { - if (intField != null) 'int-field': intField!.toString(), - if (intFieldWithDefaultValue != 1) - 'int-field-with-default-value': intFieldWithDefaultValue.toString(), + if (_self.intField != null) 'int-field': _self.intField!.toString(), + if (_self.intFieldWithDefaultValue != 1) + 'int-field-with-default-value': + _self.intFieldWithDefaultValue.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $NumRouteExtension on NumRoute { +mixin _$NumRoute on GoRouteData { static NumRoute _fromState(GoRouterState state) => NumRoute( requiredNumField: num.parse(state.pathParameters['requiredNumField']!)!, numField: _$convertMapValue( @@ -249,26 +293,34 @@ extension $NumRouteExtension on NumRoute { 1, ); + NumRoute get _self => this as NumRoute; + + @override String get location => GoRouteData.$location( - '/num-route/${Uri.encodeComponent(requiredNumField.toString())}', + '/num-route/${Uri.encodeComponent(_self.requiredNumField.toString())}', queryParams: { - if (numField != null) 'num-field': numField!.toString(), - if (numFieldWithDefaultValue != 1) - 'num-field-with-default-value': numFieldWithDefaultValue.toString(), + if (_self.numField != null) 'num-field': _self.numField!.toString(), + if (_self.numFieldWithDefaultValue != 1) + 'num-field-with-default-value': + _self.numFieldWithDefaultValue.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $EnumRouteExtension on EnumRoute { +mixin _$EnumRoute on GoRouteData { static EnumRoute _fromState(GoRouterState state) => EnumRoute( requiredEnumField: _$PersonDetailsEnumMap ._$fromName(state.pathParameters['requiredEnumField']!)!, @@ -281,24 +333,31 @@ extension $EnumRouteExtension on EnumRoute { PersonDetails.favoriteFood, ); + EnumRoute get _self => this as EnumRoute; + + @override String get location => GoRouteData.$location( - '/enum-route/${Uri.encodeComponent(_$PersonDetailsEnumMap[requiredEnumField]!)}', + '/enum-route/${Uri.encodeComponent(_$PersonDetailsEnumMap[_self.requiredEnumField]!)}', queryParams: { - if (enumField != null) - 'enum-field': _$PersonDetailsEnumMap[enumField!], - if (enumFieldWithDefaultValue != PersonDetails.favoriteFood) + if (_self.enumField != null) + 'enum-field': _$PersonDetailsEnumMap[_self.enumField!], + if (_self.enumFieldWithDefaultValue != PersonDetails.favoriteFood) 'enum-field-with-default-value': - _$PersonDetailsEnumMap[enumFieldWithDefaultValue], + _$PersonDetailsEnumMap[_self.enumFieldWithDefaultValue], }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } @@ -308,7 +367,7 @@ const _$PersonDetailsEnumMap = { PersonDetails.favoriteSport: 'favorite-sport', }; -extension $EnhancedEnumRouteExtension on EnhancedEnumRoute { +mixin _$EnhancedEnumRoute on GoRouteData { static EnhancedEnumRoute _fromState(GoRouterState state) => EnhancedEnumRoute( requiredEnumField: _$SportDetailsEnumMap ._$fromName(state.pathParameters['requiredEnumField']!)!, @@ -321,24 +380,31 @@ extension $EnhancedEnumRouteExtension on EnhancedEnumRoute { SportDetails.football, ); + EnhancedEnumRoute get _self => this as EnhancedEnumRoute; + + @override String get location => GoRouteData.$location( - '/enhanced-enum-route/${Uri.encodeComponent(_$SportDetailsEnumMap[requiredEnumField]!)}', + '/enhanced-enum-route/${Uri.encodeComponent(_$SportDetailsEnumMap[_self.requiredEnumField]!)}', queryParams: { - if (enumField != null) - 'enum-field': _$SportDetailsEnumMap[enumField!], - if (enumFieldWithDefaultValue != SportDetails.football) + if (_self.enumField != null) + 'enum-field': _$SportDetailsEnumMap[_self.enumField!], + if (_self.enumFieldWithDefaultValue != SportDetails.football) 'enum-field-with-default-value': - _$SportDetailsEnumMap[enumFieldWithDefaultValue], + _$SportDetailsEnumMap[_self.enumFieldWithDefaultValue], }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } @@ -349,7 +415,7 @@ const _$SportDetailsEnumMap = { SportDetails.hockey: 'hockey', }; -extension $StringRouteExtension on StringRoute { +mixin _$StringRoute on GoRouteData { static StringRoute _fromState(GoRouterState state) => StringRoute( requiredStringField: state.pathParameters['requiredStringField']!, stringField: state.uri.queryParameters['string-field'], @@ -358,50 +424,65 @@ extension $StringRouteExtension on StringRoute { 'defaultValue', ); + StringRoute get _self => this as StringRoute; + + @override String get location => GoRouteData.$location( - '/string-route/${Uri.encodeComponent(requiredStringField)}', + '/string-route/${Uri.encodeComponent(_self.requiredStringField)}', queryParams: { - if (stringField != null) 'string-field': stringField, - if (stringFieldWithDefaultValue != 'defaultValue') - 'string-field-with-default-value': stringFieldWithDefaultValue, + if (_self.stringField != null) 'string-field': _self.stringField, + if (_self.stringFieldWithDefaultValue != 'defaultValue') + 'string-field-with-default-value': + _self.stringFieldWithDefaultValue, }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $UriRouteExtension on UriRoute { +mixin _$UriRoute on GoRouteData { static UriRoute _fromState(GoRouterState state) => UriRoute( requiredUriField: Uri.parse(state.pathParameters['requiredUriField']!)!, uriField: _$convertMapValue( 'uri-field', state.uri.queryParameters, Uri.tryParse), ); + UriRoute get _self => this as UriRoute; + + @override String get location => GoRouteData.$location( - '/uri-route/${Uri.encodeComponent(requiredUriField.toString())}', + '/uri-route/${Uri.encodeComponent(_self.requiredUriField.toString())}', queryParams: { - if (uriField != null) 'uri-field': uriField!.toString(), + if (_self.uriField != null) 'uri-field': _self.uriField!.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $IterableRouteExtension on IterableRoute { +mixin _$IterableRoute on GoRouteData { static IterableRoute _fromState(GoRouterState state) => IterableRoute( intIterableField: (state.uri.queryParametersAll['int-iterable-field'] ?.map(int.parse) @@ -481,71 +562,84 @@ extension $IterableRouteExtension on IterableRoute { ?.toSet(), ); + IterableRoute get _self => this as IterableRoute; + + @override String get location => GoRouteData.$location( '/iterable-route', queryParams: { - if (intIterableField != null) + if (_self.intIterableField != null) 'int-iterable-field': - intIterableField?.map((e) => e.toString()).toList(), - if (doubleIterableField != null) + _self.intIterableField?.map((e) => e.toString()).toList(), + if (_self.doubleIterableField != null) 'double-iterable-field': - doubleIterableField?.map((e) => e.toString()).toList(), - if (stringIterableField != null) + _self.doubleIterableField?.map((e) => e.toString()).toList(), + if (_self.stringIterableField != null) 'string-iterable-field': - stringIterableField?.map((e) => e).toList(), - if (boolIterableField != null) + _self.stringIterableField?.map((e) => e).toList(), + if (_self.boolIterableField != null) 'bool-iterable-field': - boolIterableField?.map((e) => e.toString()).toList(), - if (enumIterableField != null) - 'enum-iterable-field': enumIterableField + _self.boolIterableField?.map((e) => e.toString()).toList(), + if (_self.enumIterableField != null) + 'enum-iterable-field': _self.enumIterableField ?.map((e) => _$SportDetailsEnumMap[e]) .toList(), - if (enumOnlyInIterableField != null) - 'enum-only-in-iterable-field': enumOnlyInIterableField + if (_self.enumOnlyInIterableField != null) + 'enum-only-in-iterable-field': _self.enumOnlyInIterableField ?.map((e) => _$CookingRecipeEnumMap[e]) .toList(), - if (intListField != null) - 'int-list-field': intListField?.map((e) => e.toString()).toList(), - if (doubleListField != null) + if (_self.intListField != null) + 'int-list-field': + _self.intListField?.map((e) => e.toString()).toList(), + if (_self.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 (enumOnlyInListField != null) - 'enum-only-in-list-field': enumOnlyInListField + _self.doubleListField?.map((e) => e.toString()).toList(), + if (_self.stringListField != null) + 'string-list-field': _self.stringListField?.map((e) => e).toList(), + if (_self.boolListField != null) + 'bool-list-field': + _self.boolListField?.map((e) => e.toString()).toList(), + if (_self.enumListField != null) + 'enum-list-field': _self.enumListField + ?.map((e) => _$SportDetailsEnumMap[e]) + .toList(), + if (_self.enumOnlyInListField != null) + 'enum-only-in-list-field': _self.enumOnlyInListField ?.map((e) => _$CookingRecipeEnumMap[e]) .toList(), - if (intSetField != null) - 'int-set-field': intSetField?.map((e) => e.toString()).toList(), - if (doubleSetField != null) + if (_self.intSetField != null) + 'int-set-field': + _self.intSetField?.map((e) => e.toString()).toList(), + if (_self.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(), - if (enumOnlyInSetField != null) - 'enum-only-in-set-field': enumOnlyInSetField + _self.doubleSetField?.map((e) => e.toString()).toList(), + if (_self.stringSetField != null) + 'string-set-field': _self.stringSetField?.map((e) => e).toList(), + if (_self.boolSetField != null) + 'bool-set-field': + _self.boolSetField?.map((e) => e.toString()).toList(), + if (_self.enumSetField != null) + 'enum-set-field': _self.enumSetField + ?.map((e) => _$SportDetailsEnumMap[e]) + .toList(), + if (_self.enumOnlyInSetField != null) + 'enum-only-in-set-field': _self.enumOnlyInSetField ?.map((e) => _$CookingRecipeEnumMap[e]) .toList(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } @@ -555,8 +649,7 @@ const _$CookingRecipeEnumMap = { CookingRecipe.tacos: 'tacos', }; -extension $IterableRouteWithDefaultValuesExtension - on IterableRouteWithDefaultValues { +mixin _$IterableRouteWithDefaultValues on GoRouteData { static IterableRouteWithDefaultValues _fromState(GoRouterState state) => IterableRouteWithDefaultValues( intIterableField: (state.uri.queryParametersAll['int-iterable-field'] @@ -636,62 +729,80 @@ extension $IterableRouteWithDefaultValuesExtension const {SportDetails.hockey}, ); + IterableRouteWithDefaultValues get _self => + this as IterableRouteWithDefaultValues; + + @override String get location => GoRouteData.$location( '/iterable-route-with-default-values', queryParams: { - if (!_$iterablesEqual(intIterableField, const [0])) + if (!_$iterablesEqual(_self.intIterableField, const [0])) 'int-iterable-field': - intIterableField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(doubleIterableField, const [0, 1, 2])) + _self.intIterableField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual( + _self.doubleIterableField, const [0, 1, 2])) 'double-iterable-field': - doubleIterableField.map((e) => e.toString()).toList(), + _self.doubleIterableField.map((e) => e.toString()).toList(), if (!_$iterablesEqual( - stringIterableField, const ['defaultValue'])) - 'string-iterable-field': stringIterableField.map((e) => e).toList(), - if (!_$iterablesEqual(boolIterableField, const [false])) + _self.stringIterableField, const ['defaultValue'])) + 'string-iterable-field': + _self.stringIterableField.map((e) => e).toList(), + if (!_$iterablesEqual(_self.boolIterableField, const [false])) 'bool-iterable-field': - boolIterableField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(enumIterableField, + _self.boolIterableField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.enumIterableField, const [SportDetails.tennis, SportDetails.hockey])) - 'enum-iterable-field': - enumIterableField.map((e) => _$SportDetailsEnumMap[e]).toList(), - if (!_$iterablesEqual(intListField, const [0])) - 'int-list-field': intListField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(doubleListField, const [1, 2, 3])) + 'enum-iterable-field': _self.enumIterableField + .map((e) => _$SportDetailsEnumMap[e]) + .toList(), + if (!_$iterablesEqual(_self.intListField, const [0])) + 'int-list-field': + _self.intListField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.doubleListField, const [1, 2, 3])) 'double-list-field': - doubleListField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(stringListField, + _self.doubleListField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.stringListField, const ['defaultValue0', 'defaultValue1'])) - 'string-list-field': stringListField.map((e) => e).toList(), - if (!_$iterablesEqual(boolListField, const [true])) - 'bool-list-field': boolListField.map((e) => e.toString()).toList(), + 'string-list-field': _self.stringListField.map((e) => e).toList(), + if (!_$iterablesEqual(_self.boolListField, const [true])) + 'bool-list-field': + _self.boolListField.map((e) => e.toString()).toList(), if (!_$iterablesEqual( - enumListField, const [SportDetails.football])) - 'enum-list-field': - enumListField.map((e) => _$SportDetailsEnumMap[e]).toList(), - if (!_$iterablesEqual(intSetField, const {0, 1})) - 'int-set-field': intSetField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(doubleSetField, const {})) + _self.enumListField, const [SportDetails.football])) + 'enum-list-field': _self.enumListField + .map((e) => _$SportDetailsEnumMap[e]) + .toList(), + if (!_$iterablesEqual(_self.intSetField, const {0, 1})) + 'int-set-field': + _self.intSetField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.doubleSetField, const {})) 'double-set-field': - doubleSetField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(stringSetField, const {'defaultValue'})) - 'string-set-field': stringSetField.map((e) => e).toList(), - if (!_$iterablesEqual(boolSetField, const {true, false})) - 'bool-set-field': boolSetField.map((e) => e.toString()).toList(), + _self.doubleSetField.map((e) => e.toString()).toList(), if (!_$iterablesEqual( - enumSetField, const {SportDetails.hockey})) - 'enum-set-field': - enumSetField.map((e) => _$SportDetailsEnumMap[e]).toList(), + _self.stringSetField, const {'defaultValue'})) + 'string-set-field': _self.stringSetField.map((e) => e).toList(), + if (!_$iterablesEqual(_self.boolSetField, const {true, false})) + 'bool-set-field': + _self.boolSetField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual( + _self.enumSetField, const {SportDetails.hockey})) + 'enum-set-field': _self.enumSetField + .map((e) => _$SportDetailsEnumMap[e]) + .toList(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/case_sensitive_example.dart b/packages/go_router_builder/example/lib/case_sensitive_example.dart index 579514064ea8..65d82e8790f9 100644 --- a/packages/go_router_builder/example/lib/case_sensitive_example.dart +++ b/packages/go_router_builder/example/lib/case_sensitive_example.dart @@ -28,7 +28,7 @@ class CaseSensitivityApp extends StatelessWidget { @TypedGoRoute( path: '/case-sensitive', ) -class CaseSensitiveRoute extends GoRouteData { +class CaseSensitiveRoute extends GoRouteData with _$CaseSensitiveRoute { const CaseSensitiveRoute(); @override @@ -41,7 +41,7 @@ class CaseSensitiveRoute extends GoRouteData { path: '/not-case-sensitive', caseSensitive: false, ) -class NotCaseSensitiveRoute extends GoRouteData { +class NotCaseSensitiveRoute extends GoRouteData with _$NotCaseSensitiveRoute { const NotCaseSensitiveRoute(); @override diff --git a/packages/go_router_builder/example/lib/case_sensitive_example.g.dart b/packages/go_router_builder/example/lib/case_sensitive_example.g.dart index e367ea7507cc..3c6a5b84e31c 100644 --- a/packages/go_router_builder/example/lib/case_sensitive_example.g.dart +++ b/packages/go_router_builder/example/lib/case_sensitive_example.g.dart @@ -15,47 +15,57 @@ List get $appRoutes => [ RouteBase get $caseSensitiveRoute => GoRouteData.$route( path: '/case-sensitive', - factory: $CaseSensitiveRouteExtension._fromState, + factory: _$CaseSensitiveRoute._fromState, ); -extension $CaseSensitiveRouteExtension on CaseSensitiveRoute { +mixin _$CaseSensitiveRoute on GoRouteData { static CaseSensitiveRoute _fromState(GoRouterState state) => const CaseSensitiveRoute(); + @override String get location => GoRouteData.$location( '/case-sensitive', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } RouteBase get $notCaseSensitiveRoute => GoRouteData.$route( path: '/not-case-sensitive', caseSensitive: false, - factory: $NotCaseSensitiveRouteExtension._fromState, + factory: _$NotCaseSensitiveRoute._fromState, ); -extension $NotCaseSensitiveRouteExtension on NotCaseSensitiveRoute { +mixin _$NotCaseSensitiveRoute on GoRouteData { static NotCaseSensitiveRoute _fromState(GoRouterState state) => const NotCaseSensitiveRoute(); + @override String get location => GoRouteData.$location( '/not-case-sensitive', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/extra_example.dart b/packages/go_router_builder/example/lib/extra_example.dart index 33547b1a6466..5f281cd4e46f 100644 --- a/packages/go_router_builder/example/lib/extra_example.dart +++ b/packages/go_router_builder/example/lib/extra_example.dart @@ -34,7 +34,7 @@ class Extra { } @TypedGoRoute(path: '/requiredExtra') -class RequiredExtraRoute extends GoRouteData { +class RequiredExtraRoute extends GoRouteData with _$RequiredExtraRoute { const RequiredExtraRoute({required this.$extra}); final Extra $extra; @@ -59,7 +59,7 @@ class RequiredExtraScreen extends StatelessWidget { } @TypedGoRoute(path: '/optionalExtra') -class OptionalExtraRoute extends GoRouteData { +class OptionalExtraRoute extends GoRouteData with _$OptionalExtraRoute { const OptionalExtraRoute({this.$extra}); final Extra? $extra; @@ -84,7 +84,7 @@ class OptionalExtraScreen extends StatelessWidget { } @TypedGoRoute(path: '/splash') -class SplashRoute extends GoRouteData { +class SplashRoute extends GoRouteData with _$SplashRoute { const SplashRoute(); @override diff --git a/packages/go_router_builder/example/lib/extra_example.g.dart b/packages/go_router_builder/example/lib/extra_example.g.dart index 7c43e54d2e58..1161326b103b 100644 --- a/packages/go_router_builder/example/lib/extra_example.g.dart +++ b/packages/go_router_builder/example/lib/extra_example.g.dart @@ -16,76 +16,95 @@ List get $appRoutes => [ RouteBase get $requiredExtraRoute => GoRouteData.$route( path: '/requiredExtra', - factory: $RequiredExtraRouteExtension._fromState, + factory: _$RequiredExtraRoute._fromState, ); -extension $RequiredExtraRouteExtension on RequiredExtraRoute { +mixin _$RequiredExtraRoute on GoRouteData { static RequiredExtraRoute _fromState(GoRouterState state) => RequiredExtraRoute( $extra: state.extra as Extra, ); + RequiredExtraRoute get _self => this as RequiredExtraRoute; + + @override String get location => GoRouteData.$location( '/requiredExtra', ); - void go(BuildContext context) => context.go(location, extra: $extra); + @override + void go(BuildContext context) => context.go(location, extra: _self.$extra); + @override Future push(BuildContext context) => - context.push(location, extra: $extra); + context.push(location, extra: _self.$extra); + @override void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: $extra); + context.pushReplacement(location, extra: _self.$extra); + @override void replace(BuildContext context) => - context.replace(location, extra: $extra); + context.replace(location, extra: _self.$extra); } RouteBase get $optionalExtraRoute => GoRouteData.$route( path: '/optionalExtra', - factory: $OptionalExtraRouteExtension._fromState, + factory: _$OptionalExtraRoute._fromState, ); -extension $OptionalExtraRouteExtension on OptionalExtraRoute { +mixin _$OptionalExtraRoute on GoRouteData { static OptionalExtraRoute _fromState(GoRouterState state) => OptionalExtraRoute( $extra: state.extra as Extra?, ); + OptionalExtraRoute get _self => this as OptionalExtraRoute; + + @override String get location => GoRouteData.$location( '/optionalExtra', ); - void go(BuildContext context) => context.go(location, extra: $extra); + @override + void go(BuildContext context) => context.go(location, extra: _self.$extra); + @override Future push(BuildContext context) => - context.push(location, extra: $extra); + context.push(location, extra: _self.$extra); + @override void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: $extra); + context.pushReplacement(location, extra: _self.$extra); + @override void replace(BuildContext context) => - context.replace(location, extra: $extra); + context.replace(location, extra: _self.$extra); } RouteBase get $splashRoute => GoRouteData.$route( path: '/splash', - factory: $SplashRouteExtension._fromState, + factory: _$SplashRoute._fromState, ); -extension $SplashRouteExtension on SplashRoute { +mixin _$SplashRoute on GoRouteData { static SplashRoute _fromState(GoRouterState state) => const SplashRoute(); + @override String get location => GoRouteData.$location( '/splash', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart index d555649825ac..38136b17a9d0 100644 --- a/packages/go_router_builder/example/lib/main.dart +++ b/packages/go_router_builder/example/lib/main.dart @@ -80,7 +80,7 @@ class App extends StatelessWidget { TypedGoRoute(path: 'family-count/:count'), ], ) -class HomeRoute extends GoRouteData { +class HomeRoute extends GoRouteData with _$HomeRoute { const HomeRoute(); @override @@ -90,7 +90,7 @@ class HomeRoute extends GoRouteData { @TypedGoRoute( path: '/login', ) -class LoginRoute extends GoRouteData { +class LoginRoute extends GoRouteData with _$LoginRoute { const LoginRoute({this.fromPage}); final String? fromPage; @@ -100,7 +100,7 @@ class LoginRoute extends GoRouteData { LoginScreen(from: fromPage); } -class FamilyRoute extends GoRouteData { +class FamilyRoute extends GoRouteData with _$FamilyRoute { const FamilyRoute(this.fid); final String fid; @@ -110,7 +110,7 @@ class FamilyRoute extends GoRouteData { FamilyScreen(family: familyById(fid)); } -class PersonRoute extends GoRouteData { +class PersonRoute extends GoRouteData with _$PersonRoute { const PersonRoute(this.fid, this.pid); final String fid; @@ -124,7 +124,7 @@ class PersonRoute extends GoRouteData { } } -class PersonDetailsRoute extends GoRouteData { +class PersonDetailsRoute extends GoRouteData with _$PersonDetailsRoute { const PersonDetailsRoute(this.fid, this.pid, this.details, {this.$extra}); final String fid; @@ -150,7 +150,7 @@ class PersonDetailsRoute extends GoRouteData { } } -class FamilyCountRoute extends GoRouteData { +class FamilyCountRoute extends GoRouteData with _$FamilyCountRoute { const FamilyCountRoute(this.count); final int count; diff --git a/packages/go_router_builder/example/lib/main.g.dart b/packages/go_router_builder/example/lib/main.g.dart index ab4cbdb3540c..f631d241cc01 100644 --- a/packages/go_router_builder/example/lib/main.g.dart +++ b/packages/go_router_builder/example/lib/main.g.dart @@ -15,19 +15,19 @@ List get $appRoutes => [ RouteBase get $homeRoute => GoRouteData.$route( path: '/', - factory: $HomeRouteExtension._fromState, + factory: _$HomeRoute._fromState, routes: [ GoRouteData.$route( path: 'family/:fid', - factory: $FamilyRouteExtension._fromState, + factory: _$FamilyRoute._fromState, routes: [ GoRouteData.$route( path: 'person/:pid', - factory: $PersonRouteExtension._fromState, + factory: _$PersonRoute._fromState, routes: [ GoRouteData.$route( path: 'details/:details', - factory: $PersonDetailsRouteExtension._fromState, + factory: _$PersonDetailsRoute._fromState, ), ], ), @@ -35,68 +35,87 @@ RouteBase get $homeRoute => GoRouteData.$route( ), GoRouteData.$route( path: 'family-count/:count', - factory: $FamilyCountRouteExtension._fromState, + factory: _$FamilyCountRoute._fromState, ), ], ); -extension $HomeRouteExtension on HomeRoute { +mixin _$HomeRoute on GoRouteData { static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); + @override String get location => GoRouteData.$location( '/', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $FamilyRouteExtension on FamilyRoute { +mixin _$FamilyRoute on GoRouteData { static FamilyRoute _fromState(GoRouterState state) => FamilyRoute( state.pathParameters['fid']!, ); + FamilyRoute get _self => this as FamilyRoute; + + @override String get location => GoRouteData.$location( - '/family/${Uri.encodeComponent(fid)}', + '/family/${Uri.encodeComponent(_self.fid)}', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $PersonRouteExtension on PersonRoute { +mixin _$PersonRoute on GoRouteData { static PersonRoute _fromState(GoRouterState state) => PersonRoute( state.pathParameters['fid']!, int.parse(state.pathParameters['pid']!)!, ); + PersonRoute get _self => this as PersonRoute; + + @override String get location => GoRouteData.$location( - '/family/${Uri.encodeComponent(fid)}/person/${Uri.encodeComponent(pid.toString())}', + '/family/${Uri.encodeComponent(_self.fid)}/person/${Uri.encodeComponent(_self.pid.toString())}', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $PersonDetailsRouteExtension on PersonDetailsRoute { +mixin _$PersonDetailsRoute on GoRouteData { static PersonDetailsRoute _fromState(GoRouterState state) => PersonDetailsRoute( state.pathParameters['fid']!, @@ -105,20 +124,27 @@ extension $PersonDetailsRouteExtension on PersonDetailsRoute { $extra: state.extra as int?, ); + PersonDetailsRoute get _self => this as PersonDetailsRoute; + + @override String get location => GoRouteData.$location( - '/family/${Uri.encodeComponent(fid)}/person/${Uri.encodeComponent(pid.toString())}/details/${Uri.encodeComponent(_$PersonDetailsEnumMap[details]!)}', + '/family/${Uri.encodeComponent(_self.fid)}/person/${Uri.encodeComponent(_self.pid.toString())}/details/${Uri.encodeComponent(_$PersonDetailsEnumMap[_self.details]!)}', ); - void go(BuildContext context) => context.go(location, extra: $extra); + @override + void go(BuildContext context) => context.go(location, extra: _self.$extra); + @override Future push(BuildContext context) => - context.push(location, extra: $extra); + context.push(location, extra: _self.$extra); + @override void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: $extra); + context.pushReplacement(location, extra: _self.$extra); + @override void replace(BuildContext context) => - context.replace(location, extra: $extra); + context.replace(location, extra: _self.$extra); } const _$PersonDetailsEnumMap = { @@ -127,22 +153,29 @@ const _$PersonDetailsEnumMap = { PersonDetails.favoriteSport: 'favorite-sport', }; -extension $FamilyCountRouteExtension on FamilyCountRoute { +mixin _$FamilyCountRoute on GoRouteData { static FamilyCountRoute _fromState(GoRouterState state) => FamilyCountRoute( int.parse(state.pathParameters['count']!)!, ); + FamilyCountRoute get _self => this as FamilyCountRoute; + + @override String get location => GoRouteData.$location( - '/family-count/${Uri.encodeComponent(count.toString())}', + '/family-count/${Uri.encodeComponent(_self.count.toString())}', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } @@ -153,27 +186,34 @@ extension on Map { RouteBase get $loginRoute => GoRouteData.$route( path: '/login', - factory: $LoginRouteExtension._fromState, + factory: _$LoginRoute._fromState, ); -extension $LoginRouteExtension on LoginRoute { +mixin _$LoginRoute on GoRouteData { static LoginRoute _fromState(GoRouterState state) => LoginRoute( fromPage: state.uri.queryParameters['from-page'], ); + LoginRoute get _self => this as LoginRoute; + + @override String get location => GoRouteData.$location( '/login', queryParams: { - if (fromPage != null) 'from-page': fromPage, + if (_self.fromPage != null) 'from-page': _self.fromPage, }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/on_exit_example.dart b/packages/go_router_builder/example/lib/on_exit_example.dart index b574c852c6e4..bbd8fea19bb1 100644 --- a/packages/go_router_builder/example/lib/on_exit_example.dart +++ b/packages/go_router_builder/example/lib/on_exit_example.dart @@ -29,14 +29,14 @@ class App extends StatelessWidget { TypedGoRoute(path: 'sub-route') ], ) -class HomeRoute extends GoRouteData { +class HomeRoute extends GoRouteData with _$HomeRoute { const HomeRoute(); @override Widget build(BuildContext context, GoRouterState state) => const HomeScreen(); } -class SubRoute extends GoRouteData { +class SubRoute extends GoRouteData with _$SubRoute { const SubRoute(); @override diff --git a/packages/go_router_builder/example/lib/on_exit_example.g.dart b/packages/go_router_builder/example/lib/on_exit_example.g.dart index 8a99156d8bfe..458ccc0371b2 100644 --- a/packages/go_router_builder/example/lib/on_exit_example.g.dart +++ b/packages/go_router_builder/example/lib/on_exit_example.g.dart @@ -14,45 +14,55 @@ List get $appRoutes => [ RouteBase get $homeRoute => GoRouteData.$route( path: '/', - factory: $HomeRouteExtension._fromState, + factory: _$HomeRoute._fromState, routes: [ GoRouteData.$route( path: 'sub-route', - factory: $SubRouteExtension._fromState, + factory: _$SubRoute._fromState, ), ], ); -extension $HomeRouteExtension on HomeRoute { +mixin _$HomeRoute on GoRouteData { static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); + @override String get location => GoRouteData.$location( '/', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $SubRouteExtension on SubRoute { +mixin _$SubRoute on GoRouteData { static SubRoute _fromState(GoRouterState state) => const SubRoute(); + @override String get location => GoRouteData.$location( '/sub-route', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/readme_excerpts.dart b/packages/go_router_builder/example/lib/readme_excerpts.dart index 28eabdf1fa52..73577ef6452b 100644 --- a/packages/go_router_builder/example/lib/readme_excerpts.dart +++ b/packages/go_router_builder/example/lib/readme_excerpts.dart @@ -87,7 +87,7 @@ void otherDoc(BuildContext context) { ], ) // #docregion HomeRoute -class HomeRoute extends GoRouteData { +class HomeRoute extends GoRouteData with _$HomeRoute { const HomeRoute(); @override @@ -107,7 +107,7 @@ class RedirectRoute extends GoRouteData { // #docregion login @TypedGoRoute(path: '/login') -class LoginRoute extends GoRouteData { +class LoginRoute extends GoRouteData with _$LoginRoute { LoginRoute({this.from}); final String? from; @@ -142,7 +142,7 @@ class HomeScreen extends StatelessWidget { } } -class FamilyRoute extends GoRouteData { +class FamilyRoute extends GoRouteData with _$FamilyRoute { const FamilyRoute({this.fid}); final String? fid; @@ -218,7 +218,7 @@ class LoginScreen extends StatelessWidget { // #docregion MyRoute @TypedGoRoute(path: '/my-route') -class MyRoute extends GoRouteData { +class MyRoute extends GoRouteData with _$MyRoute { MyRoute({this.queryParameter = 'defaultValue'}); final String queryParameter; @@ -245,7 +245,7 @@ class MyScreen extends StatelessWidget { @TypedGoRoute(path: '/person') // #docregion PersonRouteWithExtra -class PersonRouteWithExtra extends GoRouteData { +class PersonRouteWithExtra extends GoRouteData with _$PersonRouteWithExtra { PersonRouteWithExtra(this.$extra); final Person? $extra; @@ -272,7 +272,8 @@ class PersonScreen extends StatelessWidget { // #docregion HotdogRouteWithEverything @TypedGoRoute(path: '/:ketchup') -class HotdogRouteWithEverything extends GoRouteData { +class HotdogRouteWithEverything extends GoRouteData + with _$HotdogRouteWithEverything { HotdogRouteWithEverything(this.ketchup, this.mustard, this.$extra); final bool ketchup; // A required path parameter. final String? mustard; // An optional query parameter. diff --git a/packages/go_router_builder/example/lib/readme_excerpts.g.dart b/packages/go_router_builder/example/lib/readme_excerpts.g.dart index f6719844df60..41148c9230f5 100644 --- a/packages/go_router_builder/example/lib/readme_excerpts.g.dart +++ b/packages/go_router_builder/example/lib/readme_excerpts.g.dart @@ -18,140 +18,173 @@ List get $appRoutes => [ RouteBase get $homeRoute => GoRouteData.$route( path: '/', - factory: $HomeRouteExtension._fromState, + factory: _$HomeRoute._fromState, routes: [ GoRouteData.$route( path: 'family/:fid', - factory: $FamilyRouteExtension._fromState, + factory: _$FamilyRoute._fromState, ), ], ); -extension $HomeRouteExtension on HomeRoute { +mixin _$HomeRoute on GoRouteData { static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); + @override String get location => GoRouteData.$location( '/', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $FamilyRouteExtension on FamilyRoute { +mixin _$FamilyRoute on GoRouteData { static FamilyRoute _fromState(GoRouterState state) => FamilyRoute( fid: state.pathParameters['fid'], ); + FamilyRoute get _self => this as FamilyRoute; + + @override String get location => GoRouteData.$location( - '/family/${Uri.encodeComponent(fid ?? '')}', + '/family/${Uri.encodeComponent(_self.fid ?? '')}', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } RouteBase get $loginRoute => GoRouteData.$route( path: '/login', - factory: $LoginRouteExtension._fromState, + factory: _$LoginRoute._fromState, ); -extension $LoginRouteExtension on LoginRoute { +mixin _$LoginRoute on GoRouteData { static LoginRoute _fromState(GoRouterState state) => LoginRoute( from: state.uri.queryParameters['from'], ); + LoginRoute get _self => this as LoginRoute; + + @override String get location => GoRouteData.$location( '/login', queryParams: { - if (from != null) 'from': from, + if (_self.from != null) 'from': _self.from, }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } RouteBase get $myRoute => GoRouteData.$route( path: '/my-route', - factory: $MyRouteExtension._fromState, + factory: _$MyRoute._fromState, ); -extension $MyRouteExtension on MyRoute { +mixin _$MyRoute on GoRouteData { static MyRoute _fromState(GoRouterState state) => MyRoute( queryParameter: state.uri.queryParameters['query-parameter'] ?? 'defaultValue', ); + MyRoute get _self => this as MyRoute; + + @override String get location => GoRouteData.$location( '/my-route', queryParams: { - if (queryParameter != 'defaultValue') - 'query-parameter': queryParameter, + if (_self.queryParameter != 'defaultValue') + 'query-parameter': _self.queryParameter, }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } RouteBase get $personRouteWithExtra => GoRouteData.$route( path: '/person', - factory: $PersonRouteWithExtraExtension._fromState, + factory: _$PersonRouteWithExtra._fromState, ); -extension $PersonRouteWithExtraExtension on PersonRouteWithExtra { +mixin _$PersonRouteWithExtra on GoRouteData { static PersonRouteWithExtra _fromState(GoRouterState state) => PersonRouteWithExtra( state.extra as Person?, ); + PersonRouteWithExtra get _self => this as PersonRouteWithExtra; + + @override String get location => GoRouteData.$location( '/person', ); - void go(BuildContext context) => context.go(location, extra: $extra); + @override + void go(BuildContext context) => context.go(location, extra: _self.$extra); + @override Future push(BuildContext context) => - context.push(location, extra: $extra); + context.push(location, extra: _self.$extra); + @override void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: $extra); + context.pushReplacement(location, extra: _self.$extra); + @override void replace(BuildContext context) => - context.replace(location, extra: $extra); + context.replace(location, extra: _self.$extra); } RouteBase get $hotdogRouteWithEverything => GoRouteData.$route( path: '/:ketchup', - factory: $HotdogRouteWithEverythingExtension._fromState, + factory: _$HotdogRouteWithEverything._fromState, ); -extension $HotdogRouteWithEverythingExtension on HotdogRouteWithEverything { +mixin _$HotdogRouteWithEverything on GoRouteData { static HotdogRouteWithEverything _fromState(GoRouterState state) => HotdogRouteWithEverything( _$boolConverter(state.pathParameters['ketchup']!)!, @@ -159,23 +192,30 @@ extension $HotdogRouteWithEverythingExtension on HotdogRouteWithEverything { state.extra as Sauce, ); + HotdogRouteWithEverything get _self => this as HotdogRouteWithEverything; + + @override String get location => GoRouteData.$location( - '/${Uri.encodeComponent(ketchup.toString())}', + '/${Uri.encodeComponent(_self.ketchup.toString())}', queryParams: { - if (mustard != null) 'mustard': mustard, + if (_self.mustard != null) 'mustard': _self.mustard, }, ); - void go(BuildContext context) => context.go(location, extra: $extra); + @override + void go(BuildContext context) => context.go(location, extra: _self.$extra); + @override Future push(BuildContext context) => - context.push(location, extra: $extra); + context.push(location, extra: _self.$extra); + @override void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: $extra); + context.pushReplacement(location, extra: _self.$extra); + @override void replace(BuildContext context) => - context.replace(location, extra: $extra); + context.replace(location, extra: _self.$extra); } bool _$boolConverter(String value) { diff --git a/packages/go_router_builder/example/lib/shell_route_example.dart b/packages/go_router_builder/example/lib/shell_route_example.dart index 93e1df207a88..fbbc078cf814 100644 --- a/packages/go_router_builder/example/lib/shell_route_example.dart +++ b/packages/go_router_builder/example/lib/shell_route_example.dart @@ -53,7 +53,7 @@ class MyShellRouteData extends ShellRouteData { } } -class FooRouteData extends GoRouteData { +class FooRouteData extends GoRouteData with _$FooRouteData { const FooRouteData(); @override @@ -62,7 +62,7 @@ class FooRouteData extends GoRouteData { } } -class BarRouteData extends GoRouteData { +class BarRouteData extends GoRouteData with _$BarRouteData { const BarRouteData(); @override @@ -133,7 +133,7 @@ class BarScreen extends StatelessWidget { } @TypedGoRoute(path: '/login') -class LoginRoute extends GoRouteData { +class LoginRoute extends GoRouteData with _$LoginRoute { const LoginRoute(); @override diff --git a/packages/go_router_builder/example/lib/shell_route_example.g.dart b/packages/go_router_builder/example/lib/shell_route_example.g.dart index bc655746b619..0b2e61ebee34 100644 --- a/packages/go_router_builder/example/lib/shell_route_example.g.dart +++ b/packages/go_router_builder/example/lib/shell_route_example.g.dart @@ -18,11 +18,11 @@ RouteBase get $myShellRouteData => ShellRouteData.$route( routes: [ GoRouteData.$route( path: '/foo', - factory: $FooRouteDataExtension._fromState, + factory: _$FooRouteData._fromState, ), GoRouteData.$route( path: '/bar', - factory: $BarRouteDataExtension._fromState, + factory: _$BarRouteData._fromState, ), ], ); @@ -32,58 +32,73 @@ extension $MyShellRouteDataExtension on MyShellRouteData { const MyShellRouteData(); } -extension $FooRouteDataExtension on FooRouteData { +mixin _$FooRouteData on GoRouteData { static FooRouteData _fromState(GoRouterState state) => const FooRouteData(); + @override String get location => GoRouteData.$location( '/foo', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $BarRouteDataExtension on BarRouteData { +mixin _$BarRouteData on GoRouteData { static BarRouteData _fromState(GoRouterState state) => const BarRouteData(); + @override String get location => GoRouteData.$location( '/bar', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } RouteBase get $loginRoute => GoRouteData.$route( path: '/login', - factory: $LoginRouteExtension._fromState, + factory: _$LoginRoute._fromState, ); -extension $LoginRouteExtension on LoginRoute { +mixin _$LoginRoute on GoRouteData { static LoginRoute _fromState(GoRouterState state) => const LoginRoute(); + @override String get location => GoRouteData.$location( '/login', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/shell_route_with_keys_example.dart b/packages/go_router_builder/example/lib/shell_route_with_keys_example.dart index 5448f7e19183..415a8f0b31b5 100644 --- a/packages/go_router_builder/example/lib/shell_route_with_keys_example.dart +++ b/packages/go_router_builder/example/lib/shell_route_with_keys_example.dart @@ -100,7 +100,7 @@ class MyShellRouteScreen extends StatelessWidget { } } -class HomeRouteData extends GoRouteData { +class HomeRouteData extends GoRouteData with _$HomeRouteData { const HomeRouteData(); @override @@ -109,7 +109,7 @@ class HomeRouteData extends GoRouteData { } } -class UsersRouteData extends GoRouteData { +class UsersRouteData extends GoRouteData with _$UsersRouteData { const UsersRouteData(); @override @@ -143,7 +143,7 @@ class DialogPage extends Page { } } -class UserRouteData extends GoRouteData { +class UserRouteData extends GoRouteData with _$UserRouteData { const UserRouteData({required this.id}); // Without this static key, the dialog will not cover the navigation rail. diff --git a/packages/go_router_builder/example/lib/shell_route_with_keys_example.g.dart b/packages/go_router_builder/example/lib/shell_route_with_keys_example.g.dart index 4a4cb4ff9a25..759588b2d286 100644 --- a/packages/go_router_builder/example/lib/shell_route_with_keys_example.g.dart +++ b/packages/go_router_builder/example/lib/shell_route_with_keys_example.g.dart @@ -18,16 +18,16 @@ RouteBase get $myShellRouteData => ShellRouteData.$route( routes: [ GoRouteData.$route( path: '/home', - factory: $HomeRouteDataExtension._fromState, + factory: _$HomeRouteData._fromState, ), GoRouteData.$route( path: '/users', - factory: $UsersRouteDataExtension._fromState, + factory: _$UsersRouteData._fromState, routes: [ GoRouteData.$route( path: ':id', parentNavigatorKey: UserRouteData.$parentNavigatorKey, - factory: $UserRouteDataExtension._fromState, + factory: _$UserRouteData._fromState, ), ], ), @@ -39,56 +39,73 @@ extension $MyShellRouteDataExtension on MyShellRouteData { const MyShellRouteData(); } -extension $HomeRouteDataExtension on HomeRouteData { +mixin _$HomeRouteData on GoRouteData { static HomeRouteData _fromState(GoRouterState state) => const HomeRouteData(); + @override String get location => GoRouteData.$location( '/home', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $UsersRouteDataExtension on UsersRouteData { +mixin _$UsersRouteData on GoRouteData { static UsersRouteData _fromState(GoRouterState state) => const UsersRouteData(); + @override String get location => GoRouteData.$location( '/users', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $UserRouteDataExtension on UserRouteData { +mixin _$UserRouteData on GoRouteData { static UserRouteData _fromState(GoRouterState state) => UserRouteData( id: int.parse(state.pathParameters['id']!)!, ); + UserRouteData get _self => this as UserRouteData; + + @override String get location => GoRouteData.$location( - '/users/${Uri.encodeComponent(id.toString())}', + '/users/${Uri.encodeComponent(_self.id.toString())}', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/shell_route_with_observers_example.dart b/packages/go_router_builder/example/lib/shell_route_with_observers_example.dart index a69e05e749ef..326068ba8bc2 100644 --- a/packages/go_router_builder/example/lib/shell_route_with_observers_example.dart +++ b/packages/go_router_builder/example/lib/shell_route_with_observers_example.dart @@ -103,7 +103,7 @@ class MyShellRouteScreen extends StatelessWidget { } } -class HomeRouteData extends GoRouteData { +class HomeRouteData extends GoRouteData with _$HomeRouteData { const HomeRouteData(); @override @@ -112,7 +112,7 @@ class HomeRouteData extends GoRouteData { } } -class UsersRouteData extends GoRouteData { +class UsersRouteData extends GoRouteData with _$UsersRouteData { const UsersRouteData(); @override @@ -146,7 +146,7 @@ class DialogPage extends Page { } } -class UserRouteData extends GoRouteData { +class UserRouteData extends GoRouteData with _$UserRouteData { const UserRouteData({required this.id}); // Without this static key, the dialog will not cover the navigation rail. diff --git a/packages/go_router_builder/example/lib/shell_route_with_observers_example.g.dart b/packages/go_router_builder/example/lib/shell_route_with_observers_example.g.dart index 52d3c58f1cb7..e510a5f3a801 100644 --- a/packages/go_router_builder/example/lib/shell_route_with_observers_example.g.dart +++ b/packages/go_router_builder/example/lib/shell_route_with_observers_example.g.dart @@ -18,15 +18,15 @@ RouteBase get $myShellRouteData => ShellRouteData.$route( routes: [ GoRouteData.$route( path: '/home', - factory: $HomeRouteDataExtension._fromState, + factory: _$HomeRouteData._fromState, ), GoRouteData.$route( path: '/users', - factory: $UsersRouteDataExtension._fromState, + factory: _$UsersRouteData._fromState, routes: [ GoRouteData.$route( path: ':id', - factory: $UserRouteDataExtension._fromState, + factory: _$UserRouteData._fromState, ), ], ), @@ -38,56 +38,73 @@ extension $MyShellRouteDataExtension on MyShellRouteData { const MyShellRouteData(); } -extension $HomeRouteDataExtension on HomeRouteData { +mixin _$HomeRouteData on GoRouteData { static HomeRouteData _fromState(GoRouterState state) => const HomeRouteData(); + @override String get location => GoRouteData.$location( '/home', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $UsersRouteDataExtension on UsersRouteData { +mixin _$UsersRouteData on GoRouteData { static UsersRouteData _fromState(GoRouterState state) => const UsersRouteData(); + @override String get location => GoRouteData.$location( '/users', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $UserRouteDataExtension on UserRouteData { +mixin _$UserRouteData on GoRouteData { static UserRouteData _fromState(GoRouterState state) => UserRouteData( id: int.parse(state.pathParameters['id']!)!, ); + UserRouteData get _self => this as UserRouteData; + + @override String get location => GoRouteData.$location( - '/users/${Uri.encodeComponent(id.toString())}', + '/users/${Uri.encodeComponent(_self.id.toString())}', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/simple_example.dart b/packages/go_router_builder/example/lib/simple_example.dart index bfef272b1861..a2e946c49e0c 100644 --- a/packages/go_router_builder/example/lib/simple_example.dart +++ b/packages/go_router_builder/example/lib/simple_example.dart @@ -32,14 +32,14 @@ class App extends StatelessWidget { TypedGoRoute(path: 'family/:familyId') ], ) -class HomeRoute extends GoRouteData { +class HomeRoute extends GoRouteData with _$HomeRoute { const HomeRoute(); @override Widget build(BuildContext context, GoRouterState state) => const HomeScreen(); } -class FamilyRoute extends GoRouteData { +class FamilyRoute extends GoRouteData with _$FamilyRoute { const FamilyRoute(this.familyId); final String 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 f87f0ac730cd..4ecd74e3cbfa 100644 --- a/packages/go_router_builder/example/lib/simple_example.g.dart +++ b/packages/go_router_builder/example/lib/simple_example.g.dart @@ -15,47 +15,59 @@ List get $appRoutes => [ RouteBase get $homeRoute => GoRouteData.$route( path: '/', name: 'Home', - factory: $HomeRouteExtension._fromState, + factory: _$HomeRoute._fromState, routes: [ GoRouteData.$route( path: 'family/:familyId', - factory: $FamilyRouteExtension._fromState, + factory: _$FamilyRoute._fromState, ), ], ); -extension $HomeRouteExtension on HomeRoute { +mixin _$HomeRoute on GoRouteData { static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); + @override String get location => GoRouteData.$location( '/', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $FamilyRouteExtension on FamilyRoute { +mixin _$FamilyRoute on GoRouteData { static FamilyRoute _fromState(GoRouterState state) => FamilyRoute( state.pathParameters['familyId']!, ); + FamilyRoute get _self => this as FamilyRoute; + + @override String get location => GoRouteData.$location( - '/family/${Uri.encodeComponent(familyId)}', + '/family/${Uri.encodeComponent(_self.familyId)}', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/stateful_shell_route_example.dart b/packages/go_router_builder/example/lib/stateful_shell_route_example.dart index ad5ba8c82fdd..6889403bc3ae 100644 --- a/packages/go_router_builder/example/lib/stateful_shell_route_example.dart +++ b/packages/go_router_builder/example/lib/stateful_shell_route_example.dart @@ -86,7 +86,7 @@ class BranchBData extends StatefulShellBranchData { static const String $restorationScopeId = 'restorationScopeId'; } -class DetailsARouteData extends GoRouteData { +class DetailsARouteData extends GoRouteData with _$DetailsARouteData { const DetailsARouteData(); @override @@ -95,7 +95,7 @@ class DetailsARouteData extends GoRouteData { } } -class DetailsBRouteData extends GoRouteData { +class DetailsBRouteData extends GoRouteData with _$DetailsBRouteData { const DetailsBRouteData(); @override diff --git a/packages/go_router_builder/example/lib/stateful_shell_route_example.g.dart b/packages/go_router_builder/example/lib/stateful_shell_route_example.g.dart index 9be15d9859a4..d0eaa8ddf6ac 100644 --- a/packages/go_router_builder/example/lib/stateful_shell_route_example.g.dart +++ b/packages/go_router_builder/example/lib/stateful_shell_route_example.g.dart @@ -21,7 +21,7 @@ RouteBase get $myShellRouteData => StatefulShellRouteData.$route( routes: [ GoRouteData.$route( path: '/detailsA', - factory: $DetailsARouteDataExtension._fromState, + factory: _$DetailsARouteData._fromState, ), ], ), @@ -31,7 +31,7 @@ RouteBase get $myShellRouteData => StatefulShellRouteData.$route( routes: [ GoRouteData.$route( path: '/detailsB', - factory: $DetailsBRouteDataExtension._fromState, + factory: _$DetailsBRouteData._fromState, ), ], ), @@ -43,38 +43,48 @@ extension $MyShellRouteDataExtension on MyShellRouteData { const MyShellRouteData(); } -extension $DetailsARouteDataExtension on DetailsARouteData { +mixin _$DetailsARouteData on GoRouteData { static DetailsARouteData _fromState(GoRouterState state) => const DetailsARouteData(); + @override String get location => GoRouteData.$location( '/detailsA', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $DetailsBRouteDataExtension on DetailsBRouteData { +mixin _$DetailsBRouteData on GoRouteData { static DetailsBRouteData _fromState(GoRouterState state) => const DetailsBRouteData(); + @override String get location => GoRouteData.$location( '/detailsB', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart index a944e7d0997a..0e05a36e9ad1 100644 --- a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart +++ b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.dart @@ -88,7 +88,7 @@ class OrdersShellBranchData extends StatefulShellBranchData { const OrdersShellBranchData(); } -class HomeRouteData extends GoRouteData { +class HomeRouteData extends GoRouteData with _$HomeRouteData { const HomeRouteData(); @override @@ -103,7 +103,7 @@ enum NotificationsPageSection { archive, } -class NotificationsRouteData extends GoRouteData { +class NotificationsRouteData extends GoRouteData with _$NotificationsRouteData { const NotificationsRouteData({ required this.section, }); @@ -118,7 +118,7 @@ class NotificationsRouteData extends GoRouteData { } } -class OrdersRouteData extends GoRouteData { +class OrdersRouteData extends GoRouteData with _$OrdersRouteData { const OrdersRouteData(); @override diff --git a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart index f86f360772d8..c7e63a1fc7ff 100644 --- a/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart +++ b/packages/go_router_builder/example/lib/stateful_shell_route_initial_location_example.g.dart @@ -19,7 +19,7 @@ RouteBase get $mainShellRouteData => StatefulShellRouteData.$route( routes: [ GoRouteData.$route( path: '/home', - factory: $HomeRouteDataExtension._fromState, + factory: _$HomeRouteData._fromState, ), ], ), @@ -28,7 +28,7 @@ RouteBase get $mainShellRouteData => StatefulShellRouteData.$route( routes: [ GoRouteData.$route( path: '/notifications/:section', - factory: $NotificationsRouteDataExtension._fromState, + factory: _$NotificationsRouteData._fromState, ), ], ), @@ -36,7 +36,7 @@ RouteBase get $mainShellRouteData => StatefulShellRouteData.$route( routes: [ GoRouteData.$route( path: '/orders', - factory: $OrdersRouteDataExtension._fromState, + factory: _$OrdersRouteData._fromState, ), ], ), @@ -48,41 +48,53 @@ extension $MainShellRouteDataExtension on MainShellRouteData { const MainShellRouteData(); } -extension $HomeRouteDataExtension on HomeRouteData { +mixin _$HomeRouteData on GoRouteData { static HomeRouteData _fromState(GoRouterState state) => const HomeRouteData(); + @override String get location => GoRouteData.$location( '/home', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } -extension $NotificationsRouteDataExtension on NotificationsRouteData { +mixin _$NotificationsRouteData on GoRouteData { static NotificationsRouteData _fromState(GoRouterState state) => NotificationsRouteData( section: _$NotificationsPageSectionEnumMap ._$fromName(state.pathParameters['section']!)!, ); + NotificationsRouteData get _self => this as NotificationsRouteData; + + @override String get location => GoRouteData.$location( - '/notifications/${Uri.encodeComponent(_$NotificationsPageSectionEnumMap[section]!)}', + '/notifications/${Uri.encodeComponent(_$NotificationsPageSectionEnumMap[_self.section]!)}', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } @@ -92,21 +104,26 @@ const _$NotificationsPageSectionEnumMap = { NotificationsPageSection.archive: 'archive', }; -extension $OrdersRouteDataExtension on OrdersRouteData { +mixin _$OrdersRouteData on GoRouteData { static OrdersRouteData _fromState(GoRouterState state) => const OrdersRouteData(); + @override String get location => GoRouteData.$location( '/orders', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index 3e4c9175bd85..d95663d15acc 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -4,6 +4,7 @@ import 'dart:collection'; +import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; @@ -237,9 +238,20 @@ class GoRouteConfig extends RouteBaseConfig { // here to ensure it matches Uri.encodeComponent nullability final DartType? type = _field(pathParameter)?.returnType; - final String value = - '\${Uri.encodeComponent(${_encodeFor(pathParameter)}${(type?.isEnum ?? false) ? '!' : (type?.isNullableType ?? false) ? "?? ''" : ''})}'; - return MapEntry(pathParameter, value); + final StringBuffer valueBuffer = StringBuffer(); + + valueBuffer.write(r'${Uri.encodeComponent('); + valueBuffer.write(_encodeFor(pathParameter)); + + if (type?.isEnum ?? false) { + valueBuffer.write('!'); + } else if (type?.isNullableType ?? false) { + valueBuffer.write("?? ''"); + } + + valueBuffer.write(')}'); + + return MapEntry(pathParameter, valueBuffer.toString()); }), ); final String location = patternToPath(_rawJoinedPath, pathParameters); @@ -271,6 +283,16 @@ class GoRouteConfig extends RouteBaseConfig { return buffer.toString(); } + String get _castedSelf { + if (_pathParams.isEmpty && + _ctorQueryParams.isEmpty && + _extraParam == null) { + return ''; + } + + return '\n$_className get $selfFieldName => this as $_className;\n'; + } + String _decodeFor(ParameterElement element) { if (element.isRequired) { if (element.type.nullabilitySuffix == NullabilitySuffix.question && @@ -328,7 +350,7 @@ class GoRouteConfig extends RouteBaseConfig { compareField(param, parameterName, param.defaultValueCode!), ); } else if (param.type.isNullableType) { - conditions.add('$parameterName != null'); + conditions.add('$selfFieldName.$parameterName != null'); } String line = ''; if (conditions.isNotEmpty) { @@ -372,29 +394,49 @@ class GoRouteConfig extends RouteBaseConfig { @override Iterable classDeclarations() => [ - _extensionDefinition, + _mixinDefinition, ..._enumDeclarations(), ]; - String get _extensionDefinition => ''' -extension $_extensionName on $_className { - static $_className _fromState(GoRouterState state) $_fromStateConstructor + String get _mixinDefinition { + final bool hasMixin = getNodeDeclaration(routeDataClass) + ?.withClause + ?.mixinTypes + .any((NamedType e) => e.name2.toString() == _mixinName) ?? + false; - String get location => GoRouteData.\$location($_locationArgs,$_locationQueryParams); + if (!hasMixin) { + throw InvalidGenerationSourceError( + 'Missing mixin clause `with $_mixinName`', + element: routeDataClass, + ); + } + return ''' +mixin $_mixinName on GoRouteData { + static $_className _fromState(GoRouterState state) $_fromStateConstructor + $_castedSelf + @override + String get location => GoRouteData.\$location($_locationArgs,$_locationQueryParams); + + @override void go(BuildContext context) => - context.go(location${_extraParam != null ? ', extra: $extraFieldName' : ''}); - + context.go(location${_extraParam != null ? ', extra: $selfFieldName.$extraFieldName' : ''}); + + @override Future push(BuildContext context) => - context.push(location${_extraParam != null ? ', extra: $extraFieldName' : ''}); - + context.push(location${_extraParam != null ? ', extra: $selfFieldName.$extraFieldName' : ''}); + + @override void pushReplacement(BuildContext context) => - context.pushReplacement(location${_extraParam != null ? ', extra: $extraFieldName' : ''}); - + context.pushReplacement(location${_extraParam != null ? ', extra: $selfFieldName.$extraFieldName' : ''}); + + @override void replace(BuildContext context) => - context.replace(location${_extraParam != null ? ', extra: $extraFieldName' : ''}); + context.replace(location${_extraParam != null ? ', extra: $selfFieldName.$extraFieldName' : ''}); } '''; + } /// Returns code representing the constant maps that contain the `enum` to /// [String] mapping for each referenced enum. @@ -420,8 +462,7 @@ extension $_extensionName on $_className { } @override - String get factorConstructorParameters => - 'factory: $_extensionName._fromState,'; + String get factorConstructorParameters => 'factory: $_mixinName._fromState,'; @override String get routeConstructorParameters => ''' @@ -688,6 +729,8 @@ RouteBase get $_routeGetterName => ${_invokesRouteConstructor()}; String get _className => routeDataClass.name; + String get _mixinName => '_\$$_className'; + String get _extensionName => '\$${_className}Extension'; String _invokesRouteConstructor() { diff --git a/packages/go_router_builder/lib/src/type_helpers.dart b/packages/go_router_builder/lib/src/type_helpers.dart index ecf7bbd30677..5f809c335d37 100644 --- a/packages/go_router_builder/lib/src/type_helpers.dart +++ b/packages/go_router_builder/lib/src/type_helpers.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:analyzer/dart/analysis/results.dart'; +import 'package:analyzer/dart/analysis/session.dart'; +import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:source_gen/source_gen.dart'; @@ -25,6 +28,9 @@ const String enumExtensionHelperName = r'_$fromName'; /// be passed to a route. const String extraFieldName = r'$extra'; +/// The name of the generated, private getter for casting `this` (the mixin) to the class type. +const String selfFieldName = '_self'; + /// Shared start of error message related to a likely code issue. const String likelyIssueMessage = 'Should never get here! File an issue!'; @@ -79,7 +85,8 @@ String decodeParameter(ParameterElement element, Set pathParameters) { String encodeField(PropertyAccessorElement element) { for (final _TypeHelper helper in _helpers) { if (helper._matchesType(element.returnType)) { - return helper._encode(element.name, element.returnType); + return helper._encode( + '$selfFieldName.${element.name}', element.returnType); } } @@ -89,13 +96,30 @@ String encodeField(PropertyAccessorElement element) { ); } +/// Returns an AstNode type from a InterfaceElement. +T? getNodeDeclaration(InterfaceElement element) { + final AnalysisSession? session = element.session; + if (session == null) { + return null; + } + + final ParsedLibraryResult parsedLibrary = + session.getParsedLibraryByElement(element.library) as ParsedLibraryResult; + final ElementDeclarationResult? declaration = + parsedLibrary.getElementDeclaration(element); + final AstNode? node = declaration?.node; + + return node is T ? node : null; +} + /// Returns the comparison of a parameter with its default value. /// /// Otherwise, throws an [InvalidGenerationSourceError]. String compareField(ParameterElement param, String value1, String value2) { for (final _TypeHelper helper in _helpers) { if (helper._matchesType(param.type)) { - return helper._compare(param.name, param.defaultValueCode!); + return helper._compare( + '$selfFieldName.${param.name}', param.defaultValueCode!); } } diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 567f8f7808bf..aeb819b55dce 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: 2.9.1 +version: 3.0.0 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_inputs/bad_path_pattern.dart b/packages/go_router_builder/test_inputs/bad_path_pattern.dart index b6c6012ecbb7..8f2d00a0f81a 100644 --- a/packages/go_router_builder/test_inputs/bad_path_pattern.dart +++ b/packages/go_router_builder/test_inputs/bad_path_pattern.dart @@ -4,5 +4,7 @@ import 'package:go_router/go_router.dart'; +mixin _$BadPathParam {} + @TypedGoRoute(path: 'bob/:id') -class BadPathParam extends GoRouteData {} +class BadPathParam extends GoRouteData with _$BadPathParam {} diff --git a/packages/go_router_builder/test_inputs/case_sensitivity.dart b/packages/go_router_builder/test_inputs/case_sensitivity.dart index 44066f2bee99..d14feedbc70e 100644 --- a/packages/go_router_builder/test_inputs/case_sensitivity.dart +++ b/packages/go_router_builder/test_inputs/case_sensitivity.dart @@ -4,11 +4,14 @@ import 'package:go_router/go_router.dart'; +mixin _$CaseSensitiveRoute {} +mixin _$NotCaseSensitiveRoute {} + @TypedGoRoute(path: '/case-sensitive-route') -class CaseSensitiveRoute extends GoRouteData {} +class CaseSensitiveRoute extends GoRouteData with _$CaseSensitiveRoute {} @TypedGoRoute( path: '/not-case-sensitive-route', caseSensitive: false, ) -class NotCaseSensitiveRoute extends GoRouteData {} +class NotCaseSensitiveRoute extends GoRouteData with _$NotCaseSensitiveRoute {} diff --git a/packages/go_router_builder/test_inputs/case_sensitivity.dart.expect b/packages/go_router_builder/test_inputs/case_sensitivity.dart.expect index 15f764162865..acbc044d5bf0 100644 --- a/packages/go_router_builder/test_inputs/case_sensitivity.dart.expect +++ b/packages/go_router_builder/test_inputs/case_sensitivity.dart.expect @@ -1,46 +1,56 @@ RouteBase get $caseSensitiveRoute => GoRouteData.$route( path: '/case-sensitive-route', - factory: $CaseSensitiveRouteExtension._fromState, + factory: _$CaseSensitiveRoute._fromState, ); -extension $CaseSensitiveRouteExtension on CaseSensitiveRoute { +mixin _$CaseSensitiveRoute on GoRouteData { static CaseSensitiveRoute _fromState(GoRouterState state) => CaseSensitiveRoute(); + @override String get location => GoRouteData.$location( '/case-sensitive-route', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } RouteBase get $notCaseSensitiveRoute => GoRouteData.$route( path: '/not-case-sensitive-route', caseSensitive: false, - factory: $NotCaseSensitiveRouteExtension._fromState, + factory: _$NotCaseSensitiveRoute._fromState, ); -extension $NotCaseSensitiveRouteExtension on NotCaseSensitiveRoute { +mixin _$NotCaseSensitiveRoute on GoRouteData { static NotCaseSensitiveRoute _fromState(GoRouterState state) => NotCaseSensitiveRoute(); + @override String get location => GoRouteData.$location( '/not-case-sensitive-route', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/default_value.dart b/packages/go_router_builder/test_inputs/default_value.dart index 209e7f4f52f3..3d04653b7aab 100644 --- a/packages/go_router_builder/test_inputs/default_value.dart +++ b/packages/go_router_builder/test_inputs/default_value.dart @@ -4,8 +4,10 @@ import 'package:go_router/go_router.dart'; +mixin _$DefaultValueRoute {} + @TypedGoRoute(path: '/default-value-route') -class DefaultValueRoute extends GoRouteData { +class DefaultValueRoute extends GoRouteData with _$DefaultValueRoute { DefaultValueRoute({this.param = 0}); final int param; } diff --git a/packages/go_router_builder/test_inputs/default_value.dart.expect b/packages/go_router_builder/test_inputs/default_value.dart.expect index 9d9d5e8ec83b..9302c4b2346c 100644 --- a/packages/go_router_builder/test_inputs/default_value.dart.expect +++ b/packages/go_router_builder/test_inputs/default_value.dart.expect @@ -1,29 +1,36 @@ RouteBase get $defaultValueRoute => GoRouteData.$route( path: '/default-value-route', - factory: $DefaultValueRouteExtension._fromState, + factory: _$DefaultValueRoute._fromState, ); -extension $DefaultValueRouteExtension on DefaultValueRoute { +mixin _$DefaultValueRoute on GoRouteData { static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute( param: _$convertMapValue('param', state.uri.queryParameters, int.parse) ?? 0, ); + DefaultValueRoute get _self => this as DefaultValueRoute; + + @override String get location => GoRouteData.$location( '/default-value-route', queryParams: { - if (param != 0) 'param': param.toString(), + if (_self.param != 0) 'param': _self.param.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/enum_parameter.dart b/packages/go_router_builder/test_inputs/enum_parameter.dart index 72b41486b881..ce1492338bb3 100644 --- a/packages/go_router_builder/test_inputs/enum_parameter.dart +++ b/packages/go_router_builder/test_inputs/enum_parameter.dart @@ -4,8 +4,10 @@ import 'package:go_router/go_router.dart'; +mixin _$EnumParam {} + @TypedGoRoute(path: '/:y') -class EnumParam extends GoRouteData { +class EnumParam extends GoRouteData with _$EnumParam { EnumParam({required this.y}); final EnumTest y; } diff --git a/packages/go_router_builder/test_inputs/enum_parameter.dart.expect b/packages/go_router_builder/test_inputs/enum_parameter.dart.expect index 42d27809f85a..341e1bab2824 100644 --- a/packages/go_router_builder/test_inputs/enum_parameter.dart.expect +++ b/packages/go_router_builder/test_inputs/enum_parameter.dart.expect @@ -1,24 +1,31 @@ RouteBase get $enumParam => GoRouteData.$route( path: '/:y', - factory: $EnumParamExtension._fromState, + factory: _$EnumParam._fromState, ); -extension $EnumParamExtension on EnumParam { +mixin _$EnumParam on GoRouteData { static EnumParam _fromState(GoRouterState state) => EnumParam( y: _$EnumTestEnumMap._$fromName(state.pathParameters['y']!)!, ); + EnumParam get _self => this as EnumParam; + + @override String get location => GoRouteData.$location( - '/${Uri.encodeComponent(_$EnumTestEnumMap[y]!)}', + '/${Uri.encodeComponent(_$EnumTestEnumMap[_self.y]!)}', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/extra_value.dart b/packages/go_router_builder/test_inputs/extra_value.dart index 60e809172125..3951bea53292 100644 --- a/packages/go_router_builder/test_inputs/extra_value.dart +++ b/packages/go_router_builder/test_inputs/extra_value.dart @@ -4,8 +4,10 @@ import 'package:go_router/go_router.dart'; +mixin _$ExtraValueRoute {} + @TypedGoRoute(path: '/default-value-route') -class ExtraValueRoute extends GoRouteData { +class ExtraValueRoute extends GoRouteData with _$ExtraValueRoute { ExtraValueRoute({this.param = 0, this.$extra}); final int param; final int? $extra; diff --git a/packages/go_router_builder/test_inputs/extra_value.dart.expect b/packages/go_router_builder/test_inputs/extra_value.dart.expect index fccced1ce011..944b8a4b25c6 100644 --- a/packages/go_router_builder/test_inputs/extra_value.dart.expect +++ b/packages/go_router_builder/test_inputs/extra_value.dart.expect @@ -1,9 +1,9 @@ RouteBase get $extraValueRoute => GoRouteData.$route( path: '/default-value-route', - factory: $ExtraValueRouteExtension._fromState, + factory: _$ExtraValueRoute._fromState, ); -extension $ExtraValueRouteExtension on ExtraValueRoute { +mixin _$ExtraValueRoute on GoRouteData { static ExtraValueRoute _fromState(GoRouterState state) => ExtraValueRoute( param: _$convertMapValue('param', state.uri.queryParameters, int.parse) ?? @@ -11,23 +11,30 @@ extension $ExtraValueRouteExtension on ExtraValueRoute { $extra: state.extra as int?, ); + ExtraValueRoute get _self => this as ExtraValueRoute; + + @override String get location => GoRouteData.$location( '/default-value-route', queryParams: { - if (param != 0) 'param': param.toString(), + if (_self.param != 0) 'param': _self.param.toString(), }, ); - void go(BuildContext context) => context.go(location, extra: $extra); + @override + void go(BuildContext context) => context.go(location, extra: _self.$extra); + @override Future push(BuildContext context) => - context.push(location, extra: $extra); + context.push(location, extra: _self.$extra); + @override void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: $extra); + context.pushReplacement(location, extra: _self.$extra); + @override void replace(BuildContext context) => - context.replace(location, extra: $extra); + context.replace(location, extra: _self.$extra); } T? _$convertMapValue( diff --git a/packages/go_router_builder/test_inputs/iterable_with_default_value.dart b/packages/go_router_builder/test_inputs/iterable_with_default_value.dart index 3abd7a923185..01b09784d259 100644 --- a/packages/go_router_builder/test_inputs/iterable_with_default_value.dart +++ b/packages/go_router_builder/test_inputs/iterable_with_default_value.dart @@ -4,8 +4,11 @@ import 'package:go_router/go_router.dart'; +mixin _$IterableDefaultValueRoute {} + @TypedGoRoute(path: '/iterable-default-value-route') -class IterableDefaultValueRoute extends GoRouteData { +class IterableDefaultValueRoute extends GoRouteData + with _$IterableDefaultValueRoute { IterableDefaultValueRoute({this.param = const [0]}); final Iterable param; } diff --git a/packages/go_router_builder/test_inputs/iterable_with_default_value.dart.expect b/packages/go_router_builder/test_inputs/iterable_with_default_value.dart.expect index 683a64ec7cab..35e4cb75fb5f 100644 --- a/packages/go_router_builder/test_inputs/iterable_with_default_value.dart.expect +++ b/packages/go_router_builder/test_inputs/iterable_with_default_value.dart.expect @@ -1,9 +1,9 @@ RouteBase get $iterableDefaultValueRoute => GoRouteData.$route( path: '/iterable-default-value-route', - factory: $IterableDefaultValueRouteExtension._fromState, + factory: _$IterableDefaultValueRoute._fromState, ); -extension $IterableDefaultValueRouteExtension on IterableDefaultValueRoute { +mixin _$IterableDefaultValueRoute on GoRouteData { static IterableDefaultValueRoute _fromState(GoRouterState state) => IterableDefaultValueRoute( param: (state.uri.queryParametersAll['param'] @@ -12,21 +12,28 @@ extension $IterableDefaultValueRouteExtension on IterableDefaultValueRoute { const [0], ); + IterableDefaultValueRoute get _self => this as IterableDefaultValueRoute; + + @override String get location => GoRouteData.$location( '/iterable-default-value-route', queryParams: { - if (!_$iterablesEqual(param, const [0])) - 'param': param.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.param, const [0])) + 'param': _self.param.map((e) => e.toString()).toList(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/iterable_with_enum.dart b/packages/go_router_builder/test_inputs/iterable_with_enum.dart index afdb7689c7b2..0c0543ca2895 100644 --- a/packages/go_router_builder/test_inputs/iterable_with_enum.dart +++ b/packages/go_router_builder/test_inputs/iterable_with_enum.dart @@ -4,8 +4,10 @@ import 'package:go_router/go_router.dart'; +mixin _$IterableWithEnumRoute {} + @TypedGoRoute(path: '/iterable-with-enum') -class IterableWithEnumRoute extends GoRouteData { +class IterableWithEnumRoute extends GoRouteData with _$IterableWithEnumRoute { IterableWithEnumRoute({this.param}); final Iterable? param; diff --git a/packages/go_router_builder/test_inputs/iterable_with_enum.dart.expect b/packages/go_router_builder/test_inputs/iterable_with_enum.dart.expect index 88a9f97dc273..ef7fd9fec7c6 100644 --- a/packages/go_router_builder/test_inputs/iterable_with_enum.dart.expect +++ b/packages/go_router_builder/test_inputs/iterable_with_enum.dart.expect @@ -1,9 +1,9 @@ RouteBase get $iterableWithEnumRoute => GoRouteData.$route( path: '/iterable-with-enum', - factory: $IterableWithEnumRouteExtension._fromState, + factory: _$IterableWithEnumRoute._fromState, ); -extension $IterableWithEnumRouteExtension on IterableWithEnumRoute { +mixin _$IterableWithEnumRoute on GoRouteData { static IterableWithEnumRoute _fromState(GoRouterState state) => IterableWithEnumRoute( param: (state.uri.queryParametersAll['param'] @@ -12,22 +12,30 @@ extension $IterableWithEnumRouteExtension on IterableWithEnumRoute { as Iterable?), ); + IterableWithEnumRoute get _self => this as IterableWithEnumRoute; + + @override String get location => GoRouteData.$location( '/iterable-with-enum', queryParams: { - if (param != null) - 'param': - param?.map((e) => _$EnumOnlyUsedInIterableEnumMap[e]).toList(), + if (_self.param != null) + 'param': _self.param + ?.map((e) => _$EnumOnlyUsedInIterableEnumMap[e]) + .toList(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/list.dart b/packages/go_router_builder/test_inputs/list.dart index e7b3e3d975dd..07762f57bfb5 100644 --- a/packages/go_router_builder/test_inputs/list.dart +++ b/packages/go_router_builder/test_inputs/list.dart @@ -4,8 +4,10 @@ import 'package:go_router/go_router.dart'; +mixin _$ListRoute {} + @TypedGoRoute(path: '/list-route') -class ListRoute extends GoRouteData { +class ListRoute extends GoRouteData with _$ListRoute { ListRoute({ required this.ids, this.nullableIds, diff --git a/packages/go_router_builder/test_inputs/list.dart.expect b/packages/go_router_builder/test_inputs/list.dart.expect index bd7563141842..abe23c4c4f1f 100644 --- a/packages/go_router_builder/test_inputs/list.dart.expect +++ b/packages/go_router_builder/test_inputs/list.dart.expect @@ -1,9 +1,9 @@ RouteBase get $listRoute => GoRouteData.$route( path: '/list-route', - factory: $ListRouteExtension._fromState, + factory: _$ListRoute._fromState, ); -extension $ListRouteExtension on ListRoute { +mixin _$ListRoute on GoRouteData { static ListRoute _fromState(GoRouterState state) => ListRoute( ids: (state.uri.queryParametersAll['ids'] ?.map(int.parse) @@ -25,25 +25,33 @@ extension $ListRouteExtension on ListRoute { const [0], ); + ListRoute get _self => this as ListRoute; + + @override String get location => GoRouteData.$location( '/list-route', queryParams: { - 'ids': ids.map((e) => e.toString()).toList(), - if (nullableIds != null) - 'nullable-ids': nullableIds?.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(idsWithDefaultValue, const [0])) + 'ids': _self.ids.map((e) => e.toString()).toList(), + if (_self.nullableIds != null) + 'nullable-ids': + _self.nullableIds?.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.idsWithDefaultValue, const [0])) 'ids-with-default-value': - idsWithDefaultValue.map((e) => e.toString()).toList(), + _self.idsWithDefaultValue.map((e) => e.toString()).toList(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/missing_type_annotation.dart b/packages/go_router_builder/test_inputs/missing_type_annotation.dart index 2b3ff58dda56..93e65ea6b889 100644 --- a/packages/go_router_builder/test_inputs/missing_type_annotation.dart +++ b/packages/go_router_builder/test_inputs/missing_type_annotation.dart @@ -4,5 +4,7 @@ import 'package:go_router/go_router.dart'; +mixin _$MissingTypeAnnotation {} + @TypedGoRoute(path: 'bob') -class MissingTypeAnnotation extends GoRouteData {} +class MissingTypeAnnotation extends GoRouteData with _$MissingTypeAnnotation {} diff --git a/packages/go_router_builder/test_inputs/named_escaped_route.dart b/packages/go_router_builder/test_inputs/named_escaped_route.dart index eb5e26bc563e..6222aa74873a 100644 --- a/packages/go_router_builder/test_inputs/named_escaped_route.dart +++ b/packages/go_router_builder/test_inputs/named_escaped_route.dart @@ -4,5 +4,7 @@ import 'package:go_router/go_router.dart'; +mixin _$NamedEscapedRoute {} + @TypedGoRoute(path: '/named-route', name: r'named$Route') -class NamedEscapedRoute extends GoRouteData {} +class NamedEscapedRoute extends GoRouteData with _$NamedEscapedRoute {} diff --git a/packages/go_router_builder/test_inputs/named_escaped_route.dart.expect b/packages/go_router_builder/test_inputs/named_escaped_route.dart.expect index e4d75ec81631..df9ab5f52d58 100644 --- a/packages/go_router_builder/test_inputs/named_escaped_route.dart.expect +++ b/packages/go_router_builder/test_inputs/named_escaped_route.dart.expect @@ -1,23 +1,28 @@ RouteBase get $namedEscapedRoute => GoRouteData.$route( path: '/named-route', name: r'named$Route', - factory: $NamedEscapedRouteExtension._fromState, + factory: _$NamedEscapedRoute._fromState, ); -extension $NamedEscapedRouteExtension on NamedEscapedRoute { +mixin _$NamedEscapedRoute on GoRouteData { static NamedEscapedRoute _fromState(GoRouterState state) => NamedEscapedRoute(); + @override String get location => GoRouteData.$location( '/named-route', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/named_route.dart b/packages/go_router_builder/test_inputs/named_route.dart index 3e45f7e476f4..449b9537c6db 100644 --- a/packages/go_router_builder/test_inputs/named_route.dart +++ b/packages/go_router_builder/test_inputs/named_route.dart @@ -4,5 +4,7 @@ import 'package:go_router/go_router.dart'; +mixin _$NamedRoute {} + @TypedGoRoute(path: '/named-route', name: 'namedRoute') -class NamedRoute extends GoRouteData {} +class NamedRoute extends GoRouteData with _$NamedRoute {} diff --git a/packages/go_router_builder/test_inputs/named_route.dart.expect b/packages/go_router_builder/test_inputs/named_route.dart.expect index 9d4b705530cf..b3cf1c42c42f 100644 --- a/packages/go_router_builder/test_inputs/named_route.dart.expect +++ b/packages/go_router_builder/test_inputs/named_route.dart.expect @@ -1,22 +1,27 @@ RouteBase get $namedRoute => GoRouteData.$route( path: '/named-route', name: 'namedRoute', - factory: $NamedRouteExtension._fromState, + factory: _$NamedRoute._fromState, ); -extension $NamedRouteExtension on NamedRoute { +mixin _$NamedRoute on GoRouteData { static NamedRoute _fromState(GoRouterState state) => NamedRoute(); + @override String get location => GoRouteData.$location( '/named-route', ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/no_mixin.dart b/packages/go_router_builder/test_inputs/no_mixin.dart new file mode 100644 index 000000000000..b894313adb1f --- /dev/null +++ b/packages/go_router_builder/test_inputs/no_mixin.dart @@ -0,0 +1,8 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:go_router/go_router.dart'; + +@TypedGoRoute(path: '/') +class HomeRoute extends GoRouteData {} diff --git a/packages/go_router_builder/test_inputs/no_mixin.dart.expect b/packages/go_router_builder/test_inputs/no_mixin.dart.expect new file mode 100644 index 000000000000..dc98f351c1fa --- /dev/null +++ b/packages/go_router_builder/test_inputs/no_mixin.dart.expect @@ -0,0 +1 @@ +Missing mixin clause `with _$HomeRoute` diff --git a/packages/go_router_builder/test_inputs/nullable_default_value.dart b/packages/go_router_builder/test_inputs/nullable_default_value.dart index dcf2ea8e9f1b..b41f5733e01e 100644 --- a/packages/go_router_builder/test_inputs/nullable_default_value.dart +++ b/packages/go_router_builder/test_inputs/nullable_default_value.dart @@ -4,8 +4,11 @@ import 'package:go_router/go_router.dart'; +mixin _$NullableDefaultValueRoute {} + @TypedGoRoute(path: '/nullable-default-value-route') -class NullableDefaultValueRoute extends GoRouteData { +class NullableDefaultValueRoute extends GoRouteData + with _$NullableDefaultValueRoute { NullableDefaultValueRoute({this.param = 0}); final int? param; } diff --git a/packages/go_router_builder/test_inputs/required_extra_value.dart b/packages/go_router_builder/test_inputs/required_extra_value.dart index 98d6e7a94693..7c244b5b85c9 100644 --- a/packages/go_router_builder/test_inputs/required_extra_value.dart +++ b/packages/go_router_builder/test_inputs/required_extra_value.dart @@ -4,8 +4,11 @@ import 'package:go_router/go_router.dart'; +mixin _$RequiredExtraValueRoute {} + @TypedGoRoute(path: '/default-value-route') -class RequiredExtraValueRoute extends GoRouteData { +class RequiredExtraValueRoute extends GoRouteData + with _$RequiredExtraValueRoute { RequiredExtraValueRoute({required this.$extra}); final int $extra; } diff --git a/packages/go_router_builder/test_inputs/required_extra_value.dart.expect b/packages/go_router_builder/test_inputs/required_extra_value.dart.expect index 108cb1244588..662c55b67584 100644 --- a/packages/go_router_builder/test_inputs/required_extra_value.dart.expect +++ b/packages/go_router_builder/test_inputs/required_extra_value.dart.expect @@ -1,26 +1,33 @@ RouteBase get $requiredExtraValueRoute => GoRouteData.$route( path: '/default-value-route', - factory: $RequiredExtraValueRouteExtension._fromState, + factory: _$RequiredExtraValueRoute._fromState, ); -extension $RequiredExtraValueRouteExtension on RequiredExtraValueRoute { +mixin _$RequiredExtraValueRoute on GoRouteData { static RequiredExtraValueRoute _fromState(GoRouterState state) => RequiredExtraValueRoute( $extra: state.extra as int, ); + RequiredExtraValueRoute get _self => this as RequiredExtraValueRoute; + + @override String get location => GoRouteData.$location( '/default-value-route', ); - void go(BuildContext context) => context.go(location, extra: $extra); + @override + void go(BuildContext context) => context.go(location, extra: _self.$extra); + @override Future push(BuildContext context) => - context.push(location, extra: $extra); + context.push(location, extra: _self.$extra); + @override void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: $extra); + context.pushReplacement(location, extra: _self.$extra); + @override void replace(BuildContext context) => - context.replace(location, extra: $extra); + context.replace(location, extra: _self.$extra); } diff --git a/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart index 2d7f8a17ac04..88b1deeba681 100644 --- a/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart +++ b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart @@ -4,9 +4,12 @@ import 'package:go_router/go_router.dart'; +mixin _$RequiredNullableTypeArgumentsExtraValueRoute {} + @TypedGoRoute( path: '/default-value-route') -class RequiredNullableTypeArgumentsExtraValueRoute extends GoRouteData { +class RequiredNullableTypeArgumentsExtraValueRoute extends GoRouteData + with _$RequiredNullableTypeArgumentsExtraValueRoute { RequiredNullableTypeArgumentsExtraValueRoute({required this.$extra}); final List $extra; } diff --git a/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect index 9877d353f4df..2a181ac85765 100644 --- a/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect +++ b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect @@ -1,30 +1,36 @@ RouteBase get $requiredNullableTypeArgumentsExtraValueRoute => GoRouteData.$route( path: '/default-value-route', - factory: - $RequiredNullableTypeArgumentsExtraValueRouteExtension._fromState, + factory: _$RequiredNullableTypeArgumentsExtraValueRoute._fromState, ); -extension $RequiredNullableTypeArgumentsExtraValueRouteExtension - on RequiredNullableTypeArgumentsExtraValueRoute { +mixin _$RequiredNullableTypeArgumentsExtraValueRoute on GoRouteData { static RequiredNullableTypeArgumentsExtraValueRoute _fromState( GoRouterState state) => RequiredNullableTypeArgumentsExtraValueRoute( $extra: state.extra as List, ); + RequiredNullableTypeArgumentsExtraValueRoute get _self => + this as RequiredNullableTypeArgumentsExtraValueRoute; + + @override String get location => GoRouteData.$location( '/default-value-route', ); - void go(BuildContext context) => context.go(location, extra: $extra); + @override + void go(BuildContext context) => context.go(location, extra: _self.$extra); + @override Future push(BuildContext context) => - context.push(location, extra: $extra); + context.push(location, extra: _self.$extra); + @override void pushReplacement(BuildContext context) => - context.pushReplacement(location, extra: $extra); + context.pushReplacement(location, extra: _self.$extra); + @override void replace(BuildContext context) => - context.replace(location, extra: $extra); + context.replace(location, extra: _self.$extra); } diff --git a/packages/go_router_builder/test_inputs/required_parameters_in_path_cannnot_be_null.dart b/packages/go_router_builder/test_inputs/required_parameters_in_path_cannnot_be_null.dart index 17cadfb6453f..33fa3b7a1d12 100644 --- a/packages/go_router_builder/test_inputs/required_parameters_in_path_cannnot_be_null.dart +++ b/packages/go_router_builder/test_inputs/required_parameters_in_path_cannnot_be_null.dart @@ -4,8 +4,11 @@ import 'package:go_router/go_router.dart'; +mixin _$NullableRequiredParamInPath {} + @TypedGoRoute(path: 'bob/:id') -class NullableRequiredParamInPath extends GoRouteData { +class NullableRequiredParamInPath extends GoRouteData + with _$NullableRequiredParamInPath { NullableRequiredParamInPath({required this.id}); final int? id; } diff --git a/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart b/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart index 60c0c58cc1ea..3b5eecc48c08 100644 --- a/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart +++ b/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart @@ -4,8 +4,11 @@ import 'package:go_router/go_router.dart'; +mixin _$NullableRequiredParamNotInPath {} + @TypedGoRoute(path: 'bob') -class NullableRequiredParamNotInPath extends GoRouteData { +class NullableRequiredParamNotInPath extends GoRouteData + with _$NullableRequiredParamNotInPath { NullableRequiredParamNotInPath({required this.id}); final int? id; } diff --git a/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart.expect b/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart.expect index 26ab06e90c2f..60c1c0f6a25c 100644 --- a/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart.expect +++ b/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart.expect @@ -1,29 +1,36 @@ RouteBase get $nullableRequiredParamNotInPath => GoRouteData.$route( path: 'bob', - factory: $NullableRequiredParamNotInPathExtension._fromState, + factory: _$NullableRequiredParamNotInPath._fromState, ); -extension $NullableRequiredParamNotInPathExtension - on NullableRequiredParamNotInPath { +mixin _$NullableRequiredParamNotInPath on GoRouteData { static NullableRequiredParamNotInPath _fromState(GoRouterState state) => NullableRequiredParamNotInPath( id: _$convertMapValue('id', state.uri.queryParameters, int.tryParse), ); + NullableRequiredParamNotInPath get _self => + this as NullableRequiredParamNotInPath; + + @override String get location => GoRouteData.$location( 'bob', queryParams: { - if (id != null) 'id': id!.toString(), + if (_self.id != null) 'id': _self.id!.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/required_query_parameter.dart b/packages/go_router_builder/test_inputs/required_query_parameter.dart index d5b5a814136d..1dd4f0c27810 100644 --- a/packages/go_router_builder/test_inputs/required_query_parameter.dart +++ b/packages/go_router_builder/test_inputs/required_query_parameter.dart @@ -4,8 +4,11 @@ import 'package:go_router/go_router.dart'; +mixin _$NonNullableRequiredParamNotInPath {} + @TypedGoRoute(path: 'bob') -class NonNullableRequiredParamNotInPath extends GoRouteData { +class NonNullableRequiredParamNotInPath extends GoRouteData + with _$NonNullableRequiredParamNotInPath { NonNullableRequiredParamNotInPath({required this.id}); final int id; } diff --git a/packages/go_router_builder/test_inputs/required_query_parameter.dart.expect b/packages/go_router_builder/test_inputs/required_query_parameter.dart.expect index aac229ed1180..23487d96d6e3 100644 --- a/packages/go_router_builder/test_inputs/required_query_parameter.dart.expect +++ b/packages/go_router_builder/test_inputs/required_query_parameter.dart.expect @@ -1,28 +1,35 @@ RouteBase get $nonNullableRequiredParamNotInPath => GoRouteData.$route( path: 'bob', - factory: $NonNullableRequiredParamNotInPathExtension._fromState, + factory: _$NonNullableRequiredParamNotInPath._fromState, ); -extension $NonNullableRequiredParamNotInPathExtension - on NonNullableRequiredParamNotInPath { +mixin _$NonNullableRequiredParamNotInPath on GoRouteData { static NonNullableRequiredParamNotInPath _fromState(GoRouterState state) => NonNullableRequiredParamNotInPath( id: int.parse(state.uri.queryParameters['id']!)!, ); + NonNullableRequiredParamNotInPath get _self => + this as NonNullableRequiredParamNotInPath; + + @override String get location => GoRouteData.$location( 'bob', queryParams: { - 'id': id.toString(), + 'id': _self.id.toString(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/set.dart b/packages/go_router_builder/test_inputs/set.dart index 286fd6b236f4..6fb05b47eeab 100644 --- a/packages/go_router_builder/test_inputs/set.dart +++ b/packages/go_router_builder/test_inputs/set.dart @@ -4,8 +4,10 @@ import 'package:go_router/go_router.dart'; +mixin _$SetRoute {} + @TypedGoRoute(path: '/set-route') -class SetRoute extends GoRouteData { +class SetRoute extends GoRouteData with _$SetRoute { SetRoute({ required this.ids, this.nullableIds, diff --git a/packages/go_router_builder/test_inputs/set.dart.expect b/packages/go_router_builder/test_inputs/set.dart.expect index a8f577bdb001..69d25393d593 100644 --- a/packages/go_router_builder/test_inputs/set.dart.expect +++ b/packages/go_router_builder/test_inputs/set.dart.expect @@ -1,9 +1,9 @@ RouteBase get $setRoute => GoRouteData.$route( path: '/set-route', - factory: $SetRouteExtension._fromState, + factory: _$SetRoute._fromState, ); -extension $SetRouteExtension on SetRoute { +mixin _$SetRoute on GoRouteData { static SetRoute _fromState(GoRouterState state) => SetRoute( ids: (state.uri.queryParametersAll['ids'] ?.map(int.parse) @@ -25,25 +25,33 @@ extension $SetRouteExtension on SetRoute { const {0}, ); + SetRoute get _self => this as SetRoute; + + @override String get location => GoRouteData.$location( '/set-route', queryParams: { - 'ids': ids.map((e) => e.toString()).toList(), - if (nullableIds != null) - 'nullable-ids': nullableIds?.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(idsWithDefaultValue, const {0})) + 'ids': _self.ids.map((e) => e.toString()).toList(), + if (_self.nullableIds != null) + 'nullable-ids': + _self.nullableIds?.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.idsWithDefaultValue, const {0})) 'ids-with-default-value': - idsWithDefaultValue.map((e) => e.toString()).toList(), + _self.idsWithDefaultValue.map((e) => e.toString()).toList(), }, ); + @override void go(BuildContext context) => context.go(location); + @override Future push(BuildContext context) => context.push(location); + @override void pushReplacement(BuildContext context) => context.pushReplacement(location); + @override void replace(BuildContext context) => context.replace(location); } diff --git a/packages/go_router_builder/test_inputs/unsupported_type.dart b/packages/go_router_builder/test_inputs/unsupported_type.dart index 55df2a674d1d..7681c3212338 100644 --- a/packages/go_router_builder/test_inputs/unsupported_type.dart +++ b/packages/go_router_builder/test_inputs/unsupported_type.dart @@ -4,8 +4,10 @@ import 'package:go_router/go_router.dart'; +mixin _$UnsupportedType {} + @TypedGoRoute(path: 'bob/:id') -class UnsupportedType extends GoRouteData { +class UnsupportedType extends GoRouteData with _$UnsupportedType { UnsupportedType({required this.id}); final Stopwatch id; }