From f5b292e52b03a3d76a43c2f7a3dd3d149aec6d2f Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 15 Aug 2025 09:28:33 -0400 Subject: [PATCH 1/3] Autoformat --- .../example/lib/all_extension_types.dart | 353 +++---- .../example/lib/all_extension_types.g.dart | 409 ++++---- .../example/lib/all_types.dart | 513 +++++---- .../example/lib/all_types.g.dart | 976 ++++++++++-------- .../example/lib/case_sensitive_example.dart | 45 +- .../example/lib/case_sensitive_example.g.dart | 27 +- .../example/lib/extra_example.dart | 12 +- .../example/lib/extra_example.g.dart | 46 +- .../go_router_builder/example/lib/main.dart | 230 ++--- .../go_router_builder/example/lib/main.g.dart | 95 +- .../example/lib/on_exit_example.dart | 64 +- .../example/lib/on_exit_example.g.dart | 27 +- .../example/lib/readme_excerpts.dart | 84 +- .../example/lib/readme_excerpts.g.dart | 193 ++-- .../example/lib/shared/data.dart | 42 +- .../example/lib/shell_route_example.dart | 26 +- .../example/lib/shell_route_example.g.dart | 41 +- .../lib/shell_route_with_keys_example.dart | 5 +- .../lib/shell_route_with_keys_example.g.dart | 50 +- .../shell_route_with_observers_example.dart | 7 +- .../shell_route_with_observers_example.g.dart | 49 +- .../example/lib/simple_example.dart | 47 +- .../example/lib/simple_example.g.dart | 38 +- .../lib/stateful_shell_route_example.dart | 88 +- .../lib/stateful_shell_route_example.g.dart | 54 +- ..._shell_route_initial_location_example.dart | 116 +-- ...hell_route_initial_location_example.g.dart | 71 +- .../go_router_builder/example/pubspec.yaml | 2 +- .../example/test/all_types_test.dart | 339 +++--- .../test/case_sensitivity_example_test.dart | 58 +- .../example/test/location_test.dart | 8 +- .../example/test/on_exit_example_test.dart | 5 +- .../example/test/simple_example_test.dart | 5 +- .../test/stateful_shell_route_test.dart | 5 +- 34 files changed, 2020 insertions(+), 2110 deletions(-) diff --git a/packages/go_router_builder/example/lib/all_extension_types.dart b/packages/go_router_builder/example/lib/all_extension_types.dart index a9949cd1eb5..4d72750c788 100644 --- a/packages/go_router_builder/example/lib/all_extension_types.dart +++ b/packages/go_router_builder/example/lib/all_extension_types.dart @@ -11,31 +11,41 @@ import 'shared/data.dart'; part 'all_extension_types.g.dart'; -@TypedGoRoute(path: '/', routes: >[ - TypedGoRoute( - path: 'big-int-route/:requiredBigIntField'), - TypedGoRoute(path: 'bool-route/:requiredBoolField'), - TypedGoRoute( - path: 'date-time-route/:requiredDateTimeField'), - TypedGoRoute(path: 'double-route/:requiredDoubleField'), - TypedGoRoute(path: 'int-route/:requiredIntField'), - TypedGoRoute(path: 'num-route/:requiredNumField'), - TypedGoRoute(path: 'double-route/:requiredDoubleField'), - TypedGoRoute(path: 'enum-route/:requiredEnumField'), - TypedGoRoute( - path: 'enhanced-enum-route/:requiredEnumField'), - TypedGoRoute(path: 'string-route/:requiredStringField'), - TypedGoRoute(path: 'uri-route/:requiredUriField'), -]) +@TypedGoRoute( + path: '/', + routes: >[ + TypedGoRoute( + path: 'big-int-route/:requiredBigIntField', + ), + TypedGoRoute(path: 'bool-route/:requiredBoolField'), + TypedGoRoute( + path: 'date-time-route/:requiredDateTimeField', + ), + TypedGoRoute( + path: 'double-route/:requiredDoubleField', + ), + TypedGoRoute(path: 'int-route/:requiredIntField'), + TypedGoRoute(path: 'num-route/:requiredNumField'), + TypedGoRoute( + path: 'double-route/:requiredDoubleField', + ), + TypedGoRoute(path: 'enum-route/:requiredEnumField'), + TypedGoRoute( + path: 'enhanced-enum-route/:requiredEnumField', + ), + TypedGoRoute( + path: 'string-route/:requiredStringField', + ), + TypedGoRoute(path: 'uri-route/:requiredUriField'), + ], +) @immutable class AllTypesBaseRoute extends GoRouteData with _$AllTypesBaseRoute { const AllTypesBaseRoute(); @override Widget build(BuildContext context, GoRouterState state) => - const BasePage( - dataTitle: 'Root', - ); + const BasePage(dataTitle: 'Root'); } extension type const BigIntExtension(BigInt value) {} @@ -60,16 +70,16 @@ class BigIntExtensionRoute extends GoRouteData with _$BigIntExtensionRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'BigIntExtensionRoute', - param: requiredBigIntField.value, - queryParam: bigIntField?.value, - ); + dataTitle: 'BigIntExtensionRoute', + param: requiredBigIntField.value, + queryParam: bigIntField?.value, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('BigIntExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('BigIntExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class BoolExtensionRoute extends GoRouteData with _$BoolExtensionRoute { @@ -85,17 +95,17 @@ class BoolExtensionRoute extends GoRouteData with _$BoolExtensionRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'BoolExtensionRoute', - param: requiredBoolField.value, - queryParam: boolField?.value, - queryParamWithDefaultValue: boolFieldWithDefaultValue.value, - ); + dataTitle: 'BoolExtensionRoute', + param: requiredBoolField.value, + queryParam: boolField?.value, + queryParamWithDefaultValue: boolFieldWithDefaultValue.value, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('BoolExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('BoolExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class DateTimeExtensionRoute extends GoRouteData with _$DateTimeExtensionRoute { @@ -109,16 +119,16 @@ class DateTimeExtensionRoute extends GoRouteData with _$DateTimeExtensionRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'DateTimeExtensionRoute', - param: requiredDateTimeField.value, - queryParam: dateTimeField?.value, - ); + dataTitle: 'DateTimeExtensionRoute', + param: requiredDateTimeField.value, + queryParam: dateTimeField?.value, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('DateTimeExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('DateTimeExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class DoubleExtensionRoute extends GoRouteData with _$DoubleExtensionRoute { @@ -134,17 +144,17 @@ class DoubleExtensionRoute extends GoRouteData with _$DoubleExtensionRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'DoubleExtensionRoute', - param: requiredDoubleField.value, - queryParam: doubleField?.value, - queryParamWithDefaultValue: doubleFieldWithDefaultValue.value, - ); + dataTitle: 'DoubleExtensionRoute', + param: requiredDoubleField.value, + queryParam: doubleField?.value, + queryParamWithDefaultValue: doubleFieldWithDefaultValue.value, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('DoubleExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('DoubleExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class IntExtensionRoute extends GoRouteData with _$IntExtensionRoute { @@ -160,17 +170,17 @@ class IntExtensionRoute extends GoRouteData with _$IntExtensionRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'IntExtensionRoute', - param: requiredIntField.value, - queryParam: intField?.value, - queryParamWithDefaultValue: intFieldWithDefaultValue.value, - ); + dataTitle: 'IntExtensionRoute', + param: requiredIntField.value, + queryParam: intField?.value, + queryParamWithDefaultValue: intFieldWithDefaultValue.value, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('IntExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('IntExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class NumExtensionRoute extends GoRouteData with _$NumExtensionRoute { @@ -186,25 +196,26 @@ class NumExtensionRoute extends GoRouteData with _$NumExtensionRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'NumExtensionRoute', - param: requiredNumField.value, - queryParam: numField?.value, - queryParamWithDefaultValue: numFieldWithDefaultValue.value, - ); + dataTitle: 'NumExtensionRoute', + param: requiredNumField.value, + queryParam: numField?.value, + queryParamWithDefaultValue: numFieldWithDefaultValue.value, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('NumExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('NumExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class EnumExtensionRoute extends GoRouteData with _$EnumExtensionRoute { const EnumExtensionRoute({ required this.requiredEnumField, this.enumField, - this.enumFieldWithDefaultValue = - const PersonDetailsExtension(PersonDetails.favoriteFood), + this.enumFieldWithDefaultValue = const PersonDetailsExtension( + PersonDetails.favoriteFood, + ), }); final PersonDetailsExtension requiredEnumField; @@ -221,10 +232,10 @@ class EnumExtensionRoute extends GoRouteData with _$EnumExtensionRoute { ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('EnumExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('EnumExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class EnhancedEnumExtensionRoute extends GoRouteData @@ -232,8 +243,9 @@ class EnhancedEnumExtensionRoute extends GoRouteData const EnhancedEnumExtensionRoute({ required this.requiredEnumField, this.enumField, - this.enumFieldWithDefaultValue = - const SportDetailsExtension(SportDetails.football), + this.enumFieldWithDefaultValue = const SportDetailsExtension( + SportDetails.football, + ), }); final SportDetailsExtension requiredEnumField; @@ -250,10 +262,10 @@ class EnhancedEnumExtensionRoute extends GoRouteData ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('EnhancedEnumExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('EnhancedEnumExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class StringExtensionRoute extends GoRouteData with _$StringExtensionRoute { @@ -269,40 +281,37 @@ class StringExtensionRoute extends GoRouteData with _$StringExtensionRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'StringExtensionRoute', - param: requiredStringField.value, - queryParam: stringField?.value, - queryParamWithDefaultValue: stringFieldWithDefaultValue.value, - ); + dataTitle: 'StringExtensionRoute', + param: requiredStringField.value, + queryParam: stringField?.value, + queryParamWithDefaultValue: stringFieldWithDefaultValue.value, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('StringExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('StringExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class UriExtensionRoute extends GoRouteData with _$UriExtensionRoute { - const UriExtensionRoute({ - required this.requiredUriField, - this.uriField, - }); + const UriExtensionRoute({required this.requiredUriField, this.uriField}); final UriExtension requiredUriField; final UriExtension? uriField; @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'UriExtensionRoute', - param: requiredUriField.value, - queryParam: uriField?.value, - ); + dataTitle: 'UriExtensionRoute', + param: requiredUriField.value, + queryParam: uriField?.value, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('UriExtensionRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('UriExtensionRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class BasePage extends StatelessWidget { @@ -321,73 +330,72 @@ class BasePage extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar( - title: const Text('Go router extension types'), - ), - drawer: Drawer( - child: ListView( - children: [ - BigIntExtensionRoute( - requiredBigIntField: BigIntExtension(BigInt.two), - bigIntField: BigIntExtension(BigInt.zero), - ).drawerTile(context), - const BoolExtensionRoute( - requiredBoolField: BoolExtension(true), - boolField: BoolExtension(false), - ).drawerTile(context), - DateTimeExtensionRoute( - requiredDateTimeField: DateTimeExtension(DateTime(1970)), - dateTimeField: DateTimeExtension(DateTime(0)), - ).drawerTile(context), - const DoubleExtensionRoute( - requiredDoubleField: DoubleExtension(3.14), - doubleField: DoubleExtension(-3.14), - ).drawerTile(context), - const IntExtensionRoute( - requiredIntField: IntExtension(42), - intField: IntExtension(-42), - ).drawerTile(context), - const NumExtensionRoute( - requiredNumField: NumExtension(2.71828), - numField: NumExtension(-2.71828), - ).drawerTile(context), - const StringExtensionRoute( - requiredStringField: StringExtension(r'$!/#bob%%20'), - stringField: StringExtension(r'$!/#bob%%20'), - ).drawerTile(context), - const EnumExtensionRoute( - requiredEnumField: - PersonDetailsExtension(PersonDetails.favoriteSport), - enumField: PersonDetailsExtension(PersonDetails.favoriteFood), - ).drawerTile(context), - const EnhancedEnumExtensionRoute( - requiredEnumField: SportDetailsExtension(SportDetails.football), - enumField: SportDetailsExtension(SportDetails.volleyball), - ).drawerTile(context), - UriExtensionRoute( - requiredUriField: UriExtension(Uri.parse('https://dart.dev')), - uriField: UriExtension(Uri.parse('https://dart.dev')), - ).drawerTile(context), - ], - )), - body: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Text('Built with Extension Types!'), - Text(dataTitle), - Text('Param: $param'), - Text('Query param: $queryParam'), - Text( - 'Query param with default value: $queryParamWithDefaultValue', - ), - SelectableText(GoRouterState.of(context).uri.path), - SelectableText( - GoRouterState.of(context).uri.queryParameters.toString()), - ], + appBar: AppBar(title: const Text('Go router extension types')), + drawer: Drawer( + child: ListView( + children: [ + BigIntExtensionRoute( + requiredBigIntField: BigIntExtension(BigInt.two), + bigIntField: BigIntExtension(BigInt.zero), + ).drawerTile(context), + const BoolExtensionRoute( + requiredBoolField: BoolExtension(true), + boolField: BoolExtension(false), + ).drawerTile(context), + DateTimeExtensionRoute( + requiredDateTimeField: DateTimeExtension(DateTime(1970)), + dateTimeField: DateTimeExtension(DateTime(0)), + ).drawerTile(context), + const DoubleExtensionRoute( + requiredDoubleField: DoubleExtension(3.14), + doubleField: DoubleExtension(-3.14), + ).drawerTile(context), + const IntExtensionRoute( + requiredIntField: IntExtension(42), + intField: IntExtension(-42), + ).drawerTile(context), + const NumExtensionRoute( + requiredNumField: NumExtension(2.71828), + numField: NumExtension(-2.71828), + ).drawerTile(context), + const StringExtensionRoute( + requiredStringField: StringExtension(r'$!/#bob%%20'), + stringField: StringExtension(r'$!/#bob%%20'), + ).drawerTile(context), + const EnumExtensionRoute( + requiredEnumField: PersonDetailsExtension( + PersonDetails.favoriteSport, + ), + enumField: PersonDetailsExtension(PersonDetails.favoriteFood), + ).drawerTile(context), + const EnhancedEnumExtensionRoute( + requiredEnumField: SportDetailsExtension(SportDetails.football), + enumField: SportDetailsExtension(SportDetails.volleyball), + ).drawerTile(context), + UriExtensionRoute( + requiredUriField: UriExtension(Uri.parse('https://dart.dev')), + uriField: UriExtension(Uri.parse('https://dart.dev')), + ).drawerTile(context), + ], + ), + ), + body: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text('Built with Extension Types!'), + Text(dataTitle), + Text('Param: $param'), + Text('Query param: $queryParam'), + Text('Query param with default value: $queryParamWithDefaultValue'), + SelectableText(GoRouterState.of(context).uri.path), + SelectableText( + GoRouterState.of(context).uri.queryParameters.toString(), ), - ), - ); + ], + ), + ), + ); } void main() => runApp(AllExtensionTypesApp()); @@ -396,9 +404,8 @@ class AllExtensionTypesApp extends StatelessWidget { AllExtensionTypesApp({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router); late final GoRouter _router = GoRouter( debugLogDiagnostics: true, diff --git a/packages/go_router_builder/example/lib/all_extension_types.g.dart b/packages/go_router_builder/example/lib/all_extension_types.g.dart index 999e5bc607d..0dee1167340 100644 --- a/packages/go_router_builder/example/lib/all_extension_types.g.dart +++ b/packages/go_router_builder/example/lib/all_extension_types.g.dart @@ -8,69 +8,65 @@ part of 'all_extension_types.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $allTypesBaseRoute, - ]; +List get $appRoutes => [$allTypesBaseRoute]; RouteBase get $allTypesBaseRoute => GoRouteData.$route( - path: '/', - factory: _$AllTypesBaseRoute._fromState, - routes: [ - GoRouteData.$route( - path: 'big-int-route/:requiredBigIntField', - factory: _$BigIntExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'bool-route/:requiredBoolField', - factory: _$BoolExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'date-time-route/:requiredDateTimeField', - factory: _$DateTimeExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'double-route/:requiredDoubleField', - factory: _$DoubleExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'int-route/:requiredIntField', - factory: _$IntExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'num-route/:requiredNumField', - factory: _$NumExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'double-route/:requiredDoubleField', - factory: _$DoubleExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'enum-route/:requiredEnumField', - factory: _$EnumExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'enhanced-enum-route/:requiredEnumField', - factory: _$EnhancedEnumExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'string-route/:requiredStringField', - factory: _$StringExtensionRoute._fromState, - ), - GoRouteData.$route( - path: 'uri-route/:requiredUriField', - factory: _$UriExtensionRoute._fromState, - ), - ], - ); + path: '/', + factory: _$AllTypesBaseRoute._fromState, + routes: [ + GoRouteData.$route( + path: 'big-int-route/:requiredBigIntField', + factory: _$BigIntExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'bool-route/:requiredBoolField', + factory: _$BoolExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'date-time-route/:requiredDateTimeField', + factory: _$DateTimeExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'double-route/:requiredDoubleField', + factory: _$DoubleExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'int-route/:requiredIntField', + factory: _$IntExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'num-route/:requiredNumField', + factory: _$NumExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'double-route/:requiredDoubleField', + factory: _$DoubleExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'enum-route/:requiredEnumField', + factory: _$EnumExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'enhanced-enum-route/:requiredEnumField', + factory: _$EnhancedEnumExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'string-route/:requiredStringField', + factory: _$StringExtensionRoute._fromState, + ), + GoRouteData.$route( + path: 'uri-route/:requiredUriField', + factory: _$UriExtensionRoute._fromState, + ), + ], +); mixin _$AllTypesBaseRoute on GoRouteData { static AllTypesBaseRoute _fromState(GoRouterState state) => const AllTypesBaseRoute(); @override - String get location => GoRouteData.$location( - '/', - ); + String get location => GoRouteData.$location('/'); @override void go(BuildContext context) => context.go(location); @@ -101,12 +97,12 @@ mixin _$BigIntExtensionRoute on GoRouteData { @override String get location => GoRouteData.$location( - '/big-int-route/${Uri.encodeComponent(_self.requiredBigIntField.toString())}', - queryParams: { - if (_self.bigIntField != null) - 'big-int-field': _self.bigIntField!.toString(), - }, - ); + '/big-int-route/${Uri.encodeComponent(_self.requiredBigIntField.toString())}', + queryParams: { + if (_self.bigIntField != null) + 'big-int-field': _self.bigIntField!.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -123,32 +119,34 @@ mixin _$BigIntExtensionRoute on GoRouteData { } mixin _$BoolExtensionRoute on GoRouteData { - static BoolExtensionRoute _fromState(GoRouterState state) => - BoolExtensionRoute( - requiredBoolField: - bool.parse(state.pathParameters['requiredBoolField']!) - as BoolExtension, - boolField: bool.tryParse(state.uri.queryParameters['bool-field'] ?? '') + static BoolExtensionRoute _fromState( + GoRouterState state, + ) => BoolExtensionRoute( + requiredBoolField: + bool.parse(state.pathParameters['requiredBoolField']!) as BoolExtension, + boolField: + bool.tryParse(state.uri.queryParameters['bool-field'] ?? '') as BoolExtension?, - boolFieldWithDefaultValue: bool.tryParse( - state.uri.queryParameters['bool-field-with-default-value'] ?? - '') as BoolExtension? ?? - const BoolExtension(true), - ); + boolFieldWithDefaultValue: + bool.tryParse( + state.uri.queryParameters['bool-field-with-default-value'] ?? '', + ) + as BoolExtension? ?? + const BoolExtension(true), + ); BoolExtensionRoute get _self => this as BoolExtensionRoute; @override String get location => GoRouteData.$location( - '/bool-route/${Uri.encodeComponent(_self.requiredBoolField.toString())}', - queryParams: { - if (_self.boolField != null) - 'bool-field': _self.boolField!.toString(), - if (_self.boolFieldWithDefaultValue != const BoolExtension(true)) - 'bool-field-with-default-value': - _self.boolFieldWithDefaultValue.toString(), - }, - ); + '/bool-route/${Uri.encodeComponent(_self.requiredBoolField.toString())}', + queryParams: { + if (_self.boolField != null) 'bool-field': _self.boolField!.toString(), + if (_self.boolFieldWithDefaultValue != const BoolExtension(true)) + 'bool-field-with-default-value': + _self.boolFieldWithDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -170,21 +168,23 @@ mixin _$DateTimeExtensionRoute on GoRouteData { requiredDateTimeField: DateTime.parse(state.pathParameters['requiredDateTimeField']!) as DateTimeExtension, - dateTimeField: DateTime.tryParse( - state.uri.queryParameters['date-time-field'] ?? '') - as DateTimeExtension?, + dateTimeField: + DateTime.tryParse( + state.uri.queryParameters['date-time-field'] ?? '', + ) + as DateTimeExtension?, ); DateTimeExtensionRoute get _self => this as DateTimeExtensionRoute; @override String get location => GoRouteData.$location( - '/date-time-route/${Uri.encodeComponent(_self.requiredDateTimeField.toString())}', - queryParams: { - if (_self.dateTimeField != null) - 'date-time-field': _self.dateTimeField!.toString(), - }, - ); + '/date-time-route/${Uri.encodeComponent(_self.requiredDateTimeField.toString())}', + queryParams: { + if (_self.dateTimeField != null) + 'date-time-field': _self.dateTimeField!.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -209,9 +209,14 @@ mixin _$DoubleExtensionRoute on GoRouteData { doubleField: double.tryParse(state.uri.queryParameters['double-field'] ?? '') as DoubleExtension?, - doubleFieldWithDefaultValue: double.tryParse( - state.uri.queryParameters['double-field-with-default-value'] ?? - '') as DoubleExtension? ?? + doubleFieldWithDefaultValue: + double.tryParse( + state + .uri + .queryParameters['double-field-with-default-value'] ?? + '', + ) + as DoubleExtension? ?? const DoubleExtension(1.0), ); @@ -219,15 +224,15 @@ mixin _$DoubleExtensionRoute on GoRouteData { @override String get location => GoRouteData.$location( - '/double-route/${Uri.encodeComponent(_self.requiredDoubleField.toString())}', - queryParams: { - if (_self.doubleField != null) - 'double-field': _self.doubleField!.toString(), - if (_self.doubleFieldWithDefaultValue != const DoubleExtension(1.0)) - 'double-field-with-default-value': - _self.doubleFieldWithDefaultValue.toString(), - }, - ); + '/double-route/${Uri.encodeComponent(_self.requiredDoubleField.toString())}', + queryParams: { + if (_self.doubleField != null) + 'double-field': _self.doubleField!.toString(), + if (_self.doubleFieldWithDefaultValue != const DoubleExtension(1.0)) + 'double-field-with-default-value': + _self.doubleFieldWithDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -245,28 +250,31 @@ mixin _$DoubleExtensionRoute on GoRouteData { mixin _$IntExtensionRoute on GoRouteData { static IntExtensionRoute _fromState(GoRouterState state) => IntExtensionRoute( - requiredIntField: int.parse(state.pathParameters['requiredIntField']!) - as IntExtension, - intField: int.tryParse(state.uri.queryParameters['int-field'] ?? '') + requiredIntField: + int.parse(state.pathParameters['requiredIntField']!) as IntExtension, + intField: + int.tryParse(state.uri.queryParameters['int-field'] ?? '') as IntExtension?, - intFieldWithDefaultValue: int.tryParse( - state.uri.queryParameters['int-field-with-default-value'] ?? - '') as IntExtension? ?? - const IntExtension(1), - ); + intFieldWithDefaultValue: + int.tryParse( + state.uri.queryParameters['int-field-with-default-value'] ?? '', + ) + as IntExtension? ?? + const IntExtension(1), + ); IntExtensionRoute get _self => this as IntExtensionRoute; @override String get location => GoRouteData.$location( - '/int-route/${Uri.encodeComponent(_self.requiredIntField.toString())}', - queryParams: { - if (_self.intField != null) 'int-field': _self.intField!.toString(), - if (_self.intFieldWithDefaultValue != const IntExtension(1)) - 'int-field-with-default-value': - _self.intFieldWithDefaultValue.toString(), - }, - ); + '/int-route/${Uri.encodeComponent(_self.requiredIntField.toString())}', + queryParams: { + if (_self.intField != null) 'int-field': _self.intField!.toString(), + if (_self.intFieldWithDefaultValue != const IntExtension(1)) + 'int-field-with-default-value': + _self.intFieldWithDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -284,28 +292,31 @@ mixin _$IntExtensionRoute on GoRouteData { mixin _$NumExtensionRoute on GoRouteData { static NumExtensionRoute _fromState(GoRouterState state) => NumExtensionRoute( - requiredNumField: num.parse(state.pathParameters['requiredNumField']!) - as NumExtension, - numField: num.tryParse(state.uri.queryParameters['num-field'] ?? '') + requiredNumField: + num.parse(state.pathParameters['requiredNumField']!) as NumExtension, + numField: + num.tryParse(state.uri.queryParameters['num-field'] ?? '') as NumExtension?, - numFieldWithDefaultValue: num.tryParse( - state.uri.queryParameters['num-field-with-default-value'] ?? - '') as NumExtension? ?? - const NumExtension(1), - ); + numFieldWithDefaultValue: + num.tryParse( + state.uri.queryParameters['num-field-with-default-value'] ?? '', + ) + as NumExtension? ?? + const NumExtension(1), + ); NumExtensionRoute get _self => this as NumExtensionRoute; @override String get location => GoRouteData.$location( - '/num-route/${Uri.encodeComponent(_self.requiredNumField.toString())}', - queryParams: { - if (_self.numField != null) 'num-field': _self.numField!.toString(), - if (_self.numFieldWithDefaultValue != const NumExtension(1)) - 'num-field-with-default-value': - _self.numFieldWithDefaultValue.toString(), - }, - ); + '/num-route/${Uri.encodeComponent(_self.requiredNumField.toString())}', + queryParams: { + if (_self.numField != null) 'num-field': _self.numField!.toString(), + if (_self.numFieldWithDefaultValue != const NumExtension(1)) + 'num-field-with-default-value': + _self.numFieldWithDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -324,13 +335,20 @@ mixin _$NumExtensionRoute on GoRouteData { mixin _$EnumExtensionRoute on GoRouteData { static EnumExtensionRoute _fromState(GoRouterState state) => EnumExtensionRoute( - requiredEnumField: _$PersonDetailsEnumMap - ._$fromName(state.pathParameters['requiredEnumField']!) - as PersonDetailsExtension, - enumField: _$PersonDetailsEnumMap._$fromName( - state.uri.queryParameters['enum-field']) as PersonDetailsExtension?, - enumFieldWithDefaultValue: _$PersonDetailsEnumMap._$fromName( - state.uri.queryParameters['enum-field-with-default-value']) + requiredEnumField: + _$PersonDetailsEnumMap._$fromName( + state.pathParameters['requiredEnumField']!, + ) + as PersonDetailsExtension, + enumField: + _$PersonDetailsEnumMap._$fromName( + state.uri.queryParameters['enum-field'], + ) + as PersonDetailsExtension?, + enumFieldWithDefaultValue: + _$PersonDetailsEnumMap._$fromName( + state.uri.queryParameters['enum-field-with-default-value'], + ) as PersonDetailsExtension? ?? const PersonDetailsExtension(PersonDetails.favoriteFood), ); @@ -339,17 +357,18 @@ mixin _$EnumExtensionRoute on GoRouteData { @override String get location => GoRouteData.$location( - '/enum-route/${Uri.encodeComponent(_$PersonDetailsEnumMap[_self.requiredEnumField as PersonDetails]!)}', - queryParams: { - if (_self.enumField != null) - 'enum-field': - _$PersonDetailsEnumMap[_self.enumField! as PersonDetails]!, - if (_self.enumFieldWithDefaultValue != - const PersonDetailsExtension(PersonDetails.favoriteFood)) - 'enum-field-with-default-value': _$PersonDetailsEnumMap[ - _self.enumFieldWithDefaultValue as PersonDetails]!, - }, - ); + '/enum-route/${Uri.encodeComponent(_$PersonDetailsEnumMap[_self.requiredEnumField as PersonDetails]!)}', + queryParams: { + if (_self.enumField != null) + 'enum-field': + _$PersonDetailsEnumMap[_self.enumField! as PersonDetails]!, + if (_self.enumFieldWithDefaultValue != + const PersonDetailsExtension(PersonDetails.favoriteFood)) + 'enum-field-with-default-value': + _$PersonDetailsEnumMap[_self.enumFieldWithDefaultValue + as PersonDetails]!, + }, + ); @override void go(BuildContext context) => context.go(location); @@ -374,13 +393,20 @@ const _$PersonDetailsEnumMap = { mixin _$EnhancedEnumExtensionRoute on GoRouteData { static EnhancedEnumExtensionRoute _fromState(GoRouterState state) => EnhancedEnumExtensionRoute( - requiredEnumField: _$SportDetailsEnumMap - ._$fromName(state.pathParameters['requiredEnumField']!) - as SportDetailsExtension, - enumField: _$SportDetailsEnumMap._$fromName( - state.uri.queryParameters['enum-field']) as SportDetailsExtension?, - enumFieldWithDefaultValue: _$SportDetailsEnumMap._$fromName( - state.uri.queryParameters['enum-field-with-default-value']) + requiredEnumField: + _$SportDetailsEnumMap._$fromName( + state.pathParameters['requiredEnumField']!, + ) + as SportDetailsExtension, + enumField: + _$SportDetailsEnumMap._$fromName( + state.uri.queryParameters['enum-field'], + ) + as SportDetailsExtension?, + enumFieldWithDefaultValue: + _$SportDetailsEnumMap._$fromName( + state.uri.queryParameters['enum-field-with-default-value'], + ) as SportDetailsExtension? ?? const SportDetailsExtension(SportDetails.football), ); @@ -389,17 +415,17 @@ mixin _$EnhancedEnumExtensionRoute on GoRouteData { @override String get location => GoRouteData.$location( - '/enhanced-enum-route/${Uri.encodeComponent(_$SportDetailsEnumMap[_self.requiredEnumField as SportDetails]!)}', - queryParams: { - if (_self.enumField != null) - 'enum-field': - _$SportDetailsEnumMap[_self.enumField! as SportDetails]!, - if (_self.enumFieldWithDefaultValue != - const SportDetailsExtension(SportDetails.football)) - 'enum-field-with-default-value': _$SportDetailsEnumMap[ - _self.enumFieldWithDefaultValue as SportDetails]!, - }, - ); + '/enhanced-enum-route/${Uri.encodeComponent(_$SportDetailsEnumMap[_self.requiredEnumField as SportDetails]!)}', + queryParams: { + if (_self.enumField != null) + 'enum-field': _$SportDetailsEnumMap[_self.enumField! as SportDetails]!, + if (_self.enumFieldWithDefaultValue != + const SportDetailsExtension(SportDetails.football)) + 'enum-field-with-default-value': + _$SportDetailsEnumMap[_self.enumFieldWithDefaultValue + as SportDetails]!, + }, + ); @override void go(BuildContext context) => context.go(location); @@ -431,24 +457,24 @@ mixin _$StringExtensionRoute on GoRouteData { state.uri.queryParameters['string-field'] as StringExtension?, stringFieldWithDefaultValue: state.uri.queryParameters['string-field-with-default-value'] - as StringExtension? ?? - const StringExtension('defaultValue'), + as StringExtension? ?? + const StringExtension('defaultValue'), ); StringExtensionRoute get _self => this as StringExtensionRoute; @override String get location => GoRouteData.$location( - '/string-route/${Uri.encodeComponent(_self.requiredStringField as String)}', - queryParams: { - if (_self.stringField != null) - 'string-field': _self.stringField! as String, - if (_self.stringFieldWithDefaultValue != - const StringExtension('defaultValue')) - 'string-field-with-default-value': - _self.stringFieldWithDefaultValue as String, - }, - ); + '/string-route/${Uri.encodeComponent(_self.requiredStringField as String)}', + queryParams: { + if (_self.stringField != null) + 'string-field': _self.stringField! as String, + if (_self.stringFieldWithDefaultValue != + const StringExtension('defaultValue')) + 'string-field-with-default-value': + _self.stringFieldWithDefaultValue as String, + }, + ); @override void go(BuildContext context) => context.go(location); @@ -466,21 +492,22 @@ mixin _$StringExtensionRoute on GoRouteData { mixin _$UriExtensionRoute on GoRouteData { static UriExtensionRoute _fromState(GoRouterState state) => UriExtensionRoute( - requiredUriField: Uri.parse(state.pathParameters['requiredUriField']!) - as UriExtension, - uriField: Uri.tryParse(state.uri.queryParameters['uri-field'] ?? '') + requiredUriField: + Uri.parse(state.pathParameters['requiredUriField']!) as UriExtension, + uriField: + Uri.tryParse(state.uri.queryParameters['uri-field'] ?? '') as UriExtension?, - ); + ); UriExtensionRoute get _self => this as UriExtensionRoute; @override String get location => GoRouteData.$location( - '/uri-route/${Uri.encodeComponent(_self.requiredUriField.toString())}', - queryParams: { - if (_self.uriField != null) 'uri-field': _self.uriField!.toString(), - }, - ); + '/uri-route/${Uri.encodeComponent(_self.requiredUriField.toString())}', + queryParams: { + if (_self.uriField != null) 'uri-field': _self.uriField!.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/example/lib/all_types.dart b/packages/go_router_builder/example/lib/all_types.dart index 2394a5e3715..94a65af7165 100644 --- a/packages/go_router_builder/example/lib/all_types.dart +++ b/packages/go_router_builder/example/lib/all_types.dart @@ -11,55 +11,55 @@ import 'shared/data.dart'; part 'all_types.g.dart'; -@TypedGoRoute(path: '/', routes: >[ - TypedGoRoute(path: 'big-int-route/:requiredBigIntField'), - TypedGoRoute(path: 'bool-route/:requiredBoolField'), - TypedGoRoute(path: 'date-time-route/:requiredDateTimeField'), - TypedGoRoute(path: 'double-route/:requiredDoubleField'), - TypedGoRoute(path: 'int-route/:requiredIntField'), - TypedGoRoute(path: 'num-route/:requiredNumField'), - TypedGoRoute(path: 'double-route/:requiredDoubleField'), - TypedGoRoute(path: 'enum-route/:requiredEnumField'), - TypedGoRoute( - path: 'enhanced-enum-route/:requiredEnumField'), - TypedGoRoute(path: 'string-route/:requiredStringField'), - TypedGoRoute(path: 'uri-route/:requiredUriField'), - TypedGoRoute(path: 'iterable-route'), - TypedGoRoute( - path: 'iterable-route-with-default-values'), -]) +@TypedGoRoute( + path: '/', + routes: >[ + TypedGoRoute(path: 'big-int-route/:requiredBigIntField'), + TypedGoRoute(path: 'bool-route/:requiredBoolField'), + TypedGoRoute(path: 'date-time-route/:requiredDateTimeField'), + TypedGoRoute(path: 'double-route/:requiredDoubleField'), + TypedGoRoute(path: 'int-route/:requiredIntField'), + TypedGoRoute(path: 'num-route/:requiredNumField'), + TypedGoRoute(path: 'double-route/:requiredDoubleField'), + TypedGoRoute(path: 'enum-route/:requiredEnumField'), + TypedGoRoute( + path: 'enhanced-enum-route/:requiredEnumField', + ), + TypedGoRoute(path: 'string-route/:requiredStringField'), + TypedGoRoute(path: 'uri-route/:requiredUriField'), + TypedGoRoute(path: 'iterable-route'), + TypedGoRoute( + path: 'iterable-route-with-default-values', + ), + ], +) @immutable class AllTypesBaseRoute extends GoRouteData with _$AllTypesBaseRoute { const AllTypesBaseRoute(); @override Widget build(BuildContext context, GoRouterState state) => - const BasePage( - dataTitle: 'Root', - ); + const BasePage(dataTitle: 'Root'); } class BigIntRoute extends GoRouteData with _$BigIntRoute { - BigIntRoute({ - required this.requiredBigIntField, - this.bigIntField, - }); + BigIntRoute({required this.requiredBigIntField, this.bigIntField}); final BigInt requiredBigIntField; final BigInt? bigIntField; @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'BigIntRoute', - param: requiredBigIntField, - queryParam: bigIntField, - ); + dataTitle: 'BigIntRoute', + param: requiredBigIntField, + queryParam: bigIntField, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('BigIntRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('BigIntRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class BoolRoute extends GoRouteData with _$BoolRoute { @@ -75,40 +75,37 @@ class BoolRoute extends GoRouteData with _$BoolRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'BoolRoute', - param: requiredBoolField, - queryParam: boolField, - queryParamWithDefaultValue: boolFieldWithDefaultValue, - ); + dataTitle: 'BoolRoute', + param: requiredBoolField, + queryParam: boolField, + queryParamWithDefaultValue: boolFieldWithDefaultValue, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('BoolRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('BoolRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class DateTimeRoute extends GoRouteData with _$DateTimeRoute { - DateTimeRoute({ - required this.requiredDateTimeField, - this.dateTimeField, - }); + DateTimeRoute({required this.requiredDateTimeField, this.dateTimeField}); final DateTime requiredDateTimeField; final DateTime? dateTimeField; @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'DateTimeRoute', - param: requiredDateTimeField, - queryParam: dateTimeField, - ); + dataTitle: 'DateTimeRoute', + param: requiredDateTimeField, + queryParam: dateTimeField, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('DateTimeRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('DateTimeRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class DoubleRoute extends GoRouteData with _$DoubleRoute { @@ -124,17 +121,17 @@ class DoubleRoute extends GoRouteData with _$DoubleRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'DoubleRoute', - param: requiredDoubleField, - queryParam: doubleField, - queryParamWithDefaultValue: doubleFieldWithDefaultValue, - ); + dataTitle: 'DoubleRoute', + param: requiredDoubleField, + queryParam: doubleField, + queryParamWithDefaultValue: doubleFieldWithDefaultValue, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('DoubleRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('DoubleRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class IntRoute extends GoRouteData with _$IntRoute { @@ -150,17 +147,17 @@ class IntRoute extends GoRouteData with _$IntRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'IntRoute', - param: requiredIntField, - queryParam: intField, - queryParamWithDefaultValue: intFieldWithDefaultValue, - ); + dataTitle: 'IntRoute', + param: requiredIntField, + queryParam: intField, + queryParamWithDefaultValue: intFieldWithDefaultValue, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('IntRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('IntRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class NumRoute extends GoRouteData with _$NumRoute { @@ -176,17 +173,17 @@ class NumRoute extends GoRouteData with _$NumRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'NumRoute', - param: requiredNumField, - queryParam: numField, - queryParamWithDefaultValue: numFieldWithDefaultValue, - ); + dataTitle: 'NumRoute', + param: requiredNumField, + queryParam: numField, + queryParamWithDefaultValue: numFieldWithDefaultValue, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('NumRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('NumRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class EnumRoute extends GoRouteData with _$EnumRoute { @@ -210,10 +207,10 @@ class EnumRoute extends GoRouteData with _$EnumRoute { ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('EnumRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('EnumRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class EnhancedEnumRoute extends GoRouteData with _$EnhancedEnumRoute { @@ -237,10 +234,10 @@ class EnhancedEnumRoute extends GoRouteData with _$EnhancedEnumRoute { ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('EnhancedEnumRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('EnhancedEnumRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class StringRoute extends GoRouteData with _$StringRoute { @@ -256,40 +253,37 @@ class StringRoute extends GoRouteData with _$StringRoute { @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'StringRoute', - param: requiredStringField, - queryParam: stringField, - queryParamWithDefaultValue: stringFieldWithDefaultValue, - ); + dataTitle: 'StringRoute', + param: requiredStringField, + queryParam: stringField, + queryParamWithDefaultValue: stringFieldWithDefaultValue, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('StringRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('StringRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class UriRoute extends GoRouteData with _$UriRoute { - UriRoute({ - required this.requiredUriField, - this.uriField, - }); + UriRoute({required this.requiredUriField, this.uriField}); final Uri requiredUriField; final Uri? uriField; @override Widget build(BuildContext context, GoRouterState state) => BasePage( - dataTitle: 'UriRoute', - param: requiredUriField, - queryParam: uriField, - ); + dataTitle: 'UriRoute', + param: requiredUriField, + queryParam: uriField, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('UriRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('UriRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class IterableRoute extends GoRouteData with _$IterableRoute { @@ -340,29 +334,29 @@ class IterableRoute extends GoRouteData with _$IterableRoute { @override Widget build(BuildContext context, GoRouterState state) => IterablePage( - dataTitle: 'IterableRoute', - intIterableField: intIterableField, - doubleIterableField: doubleIterableField, - stringIterableField: stringIterableField, - boolIterableField: boolIterableField, - enumIterableField: enumIterableField, - intListField: intListField, - doubleListField: doubleListField, - stringListField: stringListField, - boolListField: boolListField, - enumListField: enumListField, - intSetField: intSetField, - doubleSetField: doubleSetField, - stringSetField: stringSetField, - boolSetField: boolSetField, - enumSetField: enumSetField, - ); + dataTitle: 'IterableRoute', + intIterableField: intIterableField, + doubleIterableField: doubleIterableField, + stringIterableField: stringIterableField, + boolIterableField: boolIterableField, + enumIterableField: enumIterableField, + intListField: intListField, + doubleListField: doubleListField, + stringListField: stringListField, + boolListField: boolListField, + enumListField: enumListField, + intSetField: intSetField, + doubleSetField: doubleSetField, + stringSetField: stringSetField, + boolSetField: boolSetField, + enumSetField: enumSetField, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('IterableRoute'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('IterableRoute'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class IterableRouteWithDefaultValues extends GoRouteData @@ -410,29 +404,29 @@ class IterableRouteWithDefaultValues extends GoRouteData @override Widget build(BuildContext context, GoRouterState state) => IterablePage( - dataTitle: 'IterableRouteWithDefaultValues', - intIterableField: intIterableField, - doubleIterableField: doubleIterableField, - stringIterableField: stringIterableField, - boolIterableField: boolIterableField, - enumIterableField: enumIterableField, - intListField: intListField, - doubleListField: doubleListField, - stringListField: stringListField, - boolListField: boolListField, - enumListField: enumListField, - intSetField: intSetField, - doubleSetField: doubleSetField, - stringSetField: stringSetField, - boolSetField: boolSetField, - enumSetField: enumSetField, - ); + dataTitle: 'IterableRouteWithDefaultValues', + intIterableField: intIterableField, + doubleIterableField: doubleIterableField, + stringIterableField: stringIterableField, + boolIterableField: boolIterableField, + enumIterableField: enumIterableField, + intListField: intListField, + doubleListField: doubleListField, + stringListField: stringListField, + boolListField: boolListField, + enumListField: enumListField, + intSetField: intSetField, + doubleSetField: doubleSetField, + stringSetField: stringSetField, + boolSetField: boolSetField, + enumSetField: enumSetField, + ); Widget drawerTile(BuildContext context) => ListTile( - title: const Text('IterableRouteWithDefaultValues'), - onTap: () => go(context), - selected: GoRouterState.of(context).uri.path == location, - ); + title: const Text('IterableRouteWithDefaultValues'), + onTap: () => go(context), + selected: GoRouterState.of(context).uri.path == location, + ); } class BasePage extends StatelessWidget { @@ -451,99 +445,94 @@ class BasePage extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar( - title: const Text('Go router typed routes'), - ), - drawer: Drawer( - child: ListView( - children: [ - BigIntRoute( - requiredBigIntField: BigInt.two, - bigIntField: BigInt.zero, - ).drawerTile(context), - BoolRoute( - requiredBoolField: true, - boolField: false, - ).drawerTile(context), - DateTimeRoute( - requiredDateTimeField: DateTime(1970), - dateTimeField: DateTime(0), - ).drawerTile(context), - DoubleRoute( - requiredDoubleField: 3.14, - doubleField: -3.14, - ).drawerTile(context), - IntRoute( - requiredIntField: 42, - intField: -42, - ).drawerTile(context), - NumRoute( - requiredNumField: 2.71828, - numField: -2.71828, - ).drawerTile(context), - StringRoute( - requiredStringField: r'$!/#bob%%20', - stringField: r'$!/#bob%%20', - ).drawerTile(context), - EnumRoute( - requiredEnumField: PersonDetails.favoriteSport, - enumField: PersonDetails.favoriteFood, - ).drawerTile(context), - EnhancedEnumRoute( - requiredEnumField: SportDetails.football, - enumField: SportDetails.volleyball, - ).drawerTile(context), - UriRoute( - requiredUriField: Uri.parse('https://dart.dev'), - uriField: Uri.parse('https://dart.dev'), - ).drawerTile(context), - IterableRoute( - intIterableField: [1, 2, 3], - doubleIterableField: [.3, .4, .5], - stringIterableField: ['quo usque tandem'], - boolIterableField: [true, false, false], - enumIterableField: [ - SportDetails.football, - SportDetails.hockey, - ], - intListField: [1, 2, 3], - doubleListField: [.3, .4, .5], - stringListField: ['quo usque tandem'], - boolListField: [true, false, false], - enumListField: [ - SportDetails.football, - SportDetails.hockey, - ], - intSetField: {1, 2, 3}, - doubleSetField: {.3, .4, .5}, - stringSetField: {'quo usque tandem'}, - boolSetField: {true, false}, - enumSetField: { - SportDetails.football, - SportDetails.hockey, - }, - ).drawerTile(context), - const IterableRouteWithDefaultValues().drawerTile(context), - ], - )), - body: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Text('Built!'), - Text(dataTitle), - Text('Param: $param'), - Text('Query param: $queryParam'), - Text( - 'Query param with default value: $queryParamWithDefaultValue', - ), - SelectableText(GoRouterState.of(context).uri.path), - SelectableText( - GoRouterState.of(context).uri.queryParameters.toString()), + appBar: AppBar(title: const Text('Go router typed routes')), + drawer: Drawer( + child: ListView( + children: [ + BigIntRoute( + requiredBigIntField: BigInt.two, + bigIntField: BigInt.zero, + ).drawerTile(context), + BoolRoute( + requiredBoolField: true, + boolField: false, + ).drawerTile(context), + DateTimeRoute( + requiredDateTimeField: DateTime(1970), + dateTimeField: DateTime(0), + ).drawerTile(context), + DoubleRoute( + requiredDoubleField: 3.14, + doubleField: -3.14, + ).drawerTile(context), + IntRoute(requiredIntField: 42, intField: -42).drawerTile(context), + NumRoute( + requiredNumField: 2.71828, + numField: -2.71828, + ).drawerTile(context), + StringRoute( + requiredStringField: r'$!/#bob%%20', + stringField: r'$!/#bob%%20', + ).drawerTile(context), + EnumRoute( + requiredEnumField: PersonDetails.favoriteSport, + enumField: PersonDetails.favoriteFood, + ).drawerTile(context), + EnhancedEnumRoute( + requiredEnumField: SportDetails.football, + enumField: SportDetails.volleyball, + ).drawerTile(context), + UriRoute( + requiredUriField: Uri.parse('https://dart.dev'), + uriField: Uri.parse('https://dart.dev'), + ).drawerTile(context), + IterableRoute( + intIterableField: [1, 2, 3], + doubleIterableField: [.3, .4, .5], + stringIterableField: ['quo usque tandem'], + boolIterableField: [true, false, false], + enumIterableField: [ + SportDetails.football, + SportDetails.hockey, + ], + intListField: [1, 2, 3], + doubleListField: [.3, .4, .5], + stringListField: ['quo usque tandem'], + boolListField: [true, false, false], + enumListField: [ + SportDetails.football, + SportDetails.hockey, ], + intSetField: {1, 2, 3}, + doubleSetField: {.3, .4, .5}, + stringSetField: {'quo usque tandem'}, + boolSetField: {true, false}, + enumSetField: { + SportDetails.football, + SportDetails.hockey, + }, + ).drawerTile(context), + const IterableRouteWithDefaultValues().drawerTile(context), + ], + ), + ), + body: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text('Built!'), + Text(dataTitle), + Text('Param: $param'), + Text('Query param: $queryParam'), + Text('Query param with default value: $queryParamWithDefaultValue'), + SelectableText(GoRouterState.of(context).uri.path), + SelectableText( + GoRouterState.of(context).uri.queryParameters.toString(), ), - ), - ); + ], + ), + ), + ); } void main() => runApp(AllTypesApp()); @@ -552,9 +541,8 @@ class AllTypesApp extends StatelessWidget { AllTypesApp({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router); late final GoRouter _router = GoRouter( debugLogDiagnostics: true, @@ -610,23 +598,24 @@ class IterablePage extends StatelessWidget { Widget build(BuildContext context) { return BasePage( dataTitle: dataTitle, - queryParamWithDefaultValue: ?>{ - 'intIterableField': intIterableField, - 'intListField': intListField, - 'intSetField': intSetField, - 'doubleIterableField': doubleIterableField, - 'doubleListField': doubleListField, - 'doubleSetField': doubleSetField, - 'stringIterableField': stringIterableField, - 'stringListField': stringListField, - 'stringSetField': stringSetField, - 'boolIterableField': boolIterableField, - 'boolListField': boolListField, - 'boolSetField': boolSetField, - 'enumIterableField': enumIterableField, - 'enumListField': enumListField, - 'enumSetField': enumSetField, - }.toString(), + queryParamWithDefaultValue: + ?>{ + 'intIterableField': intIterableField, + 'intListField': intListField, + 'intSetField': intSetField, + 'doubleIterableField': doubleIterableField, + 'doubleListField': doubleListField, + 'doubleSetField': doubleSetField, + 'stringIterableField': stringIterableField, + 'stringListField': stringListField, + 'stringSetField': stringSetField, + 'boolIterableField': boolIterableField, + 'boolListField': boolListField, + 'boolSetField': boolSetField, + 'enumIterableField': enumIterableField, + 'enumListField': enumListField, + 'enumSetField': enumSetField, + }.toString(), ); } } 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 6af36b14ee6..e9aa673fc5c 100644 --- a/packages/go_router_builder/example/lib/all_types.g.dart +++ b/packages/go_router_builder/example/lib/all_types.g.dart @@ -8,77 +8,73 @@ part of 'all_types.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $allTypesBaseRoute, - ]; +List get $appRoutes => [$allTypesBaseRoute]; RouteBase get $allTypesBaseRoute => GoRouteData.$route( - path: '/', - factory: _$AllTypesBaseRoute._fromState, - routes: [ - GoRouteData.$route( - path: 'big-int-route/:requiredBigIntField', - factory: _$BigIntRoute._fromState, - ), - GoRouteData.$route( - path: 'bool-route/:requiredBoolField', - factory: _$BoolRoute._fromState, - ), - GoRouteData.$route( - path: 'date-time-route/:requiredDateTimeField', - factory: _$DateTimeRoute._fromState, - ), - GoRouteData.$route( - path: 'double-route/:requiredDoubleField', - factory: _$DoubleRoute._fromState, - ), - GoRouteData.$route( - path: 'int-route/:requiredIntField', - factory: _$IntRoute._fromState, - ), - GoRouteData.$route( - path: 'num-route/:requiredNumField', - factory: _$NumRoute._fromState, - ), - GoRouteData.$route( - path: 'double-route/:requiredDoubleField', - factory: _$DoubleRoute._fromState, - ), - GoRouteData.$route( - path: 'enum-route/:requiredEnumField', - factory: _$EnumRoute._fromState, - ), - GoRouteData.$route( - path: 'enhanced-enum-route/:requiredEnumField', - factory: _$EnhancedEnumRoute._fromState, - ), - GoRouteData.$route( - path: 'string-route/:requiredStringField', - factory: _$StringRoute._fromState, - ), - GoRouteData.$route( - path: 'uri-route/:requiredUriField', - factory: _$UriRoute._fromState, - ), - GoRouteData.$route( - path: 'iterable-route', - factory: _$IterableRoute._fromState, - ), - GoRouteData.$route( - path: 'iterable-route-with-default-values', - factory: _$IterableRouteWithDefaultValues._fromState, - ), - ], - ); + path: '/', + factory: _$AllTypesBaseRoute._fromState, + routes: [ + GoRouteData.$route( + path: 'big-int-route/:requiredBigIntField', + factory: _$BigIntRoute._fromState, + ), + GoRouteData.$route( + path: 'bool-route/:requiredBoolField', + factory: _$BoolRoute._fromState, + ), + GoRouteData.$route( + path: 'date-time-route/:requiredDateTimeField', + factory: _$DateTimeRoute._fromState, + ), + GoRouteData.$route( + path: 'double-route/:requiredDoubleField', + factory: _$DoubleRoute._fromState, + ), + GoRouteData.$route( + path: 'int-route/:requiredIntField', + factory: _$IntRoute._fromState, + ), + GoRouteData.$route( + path: 'num-route/:requiredNumField', + factory: _$NumRoute._fromState, + ), + GoRouteData.$route( + path: 'double-route/:requiredDoubleField', + factory: _$DoubleRoute._fromState, + ), + GoRouteData.$route( + path: 'enum-route/:requiredEnumField', + factory: _$EnumRoute._fromState, + ), + GoRouteData.$route( + path: 'enhanced-enum-route/:requiredEnumField', + factory: _$EnhancedEnumRoute._fromState, + ), + GoRouteData.$route( + path: 'string-route/:requiredStringField', + factory: _$StringRoute._fromState, + ), + GoRouteData.$route( + path: 'uri-route/:requiredUriField', + factory: _$UriRoute._fromState, + ), + GoRouteData.$route( + path: 'iterable-route', + factory: _$IterableRoute._fromState, + ), + GoRouteData.$route( + path: 'iterable-route-with-default-values', + factory: _$IterableRouteWithDefaultValues._fromState, + ), + ], +); mixin _$AllTypesBaseRoute on GoRouteData { static AllTypesBaseRoute _fromState(GoRouterState state) => const AllTypesBaseRoute(); @override - String get location => GoRouteData.$location( - '/', - ); + String get location => GoRouteData.$location('/'); @override void go(BuildContext context) => context.go(location); @@ -96,22 +92,25 @@ mixin _$AllTypesBaseRoute on GoRouteData { mixin _$BigIntRoute on GoRouteData { static BigIntRoute _fromState(GoRouterState state) => BigIntRoute( - requiredBigIntField: - BigInt.parse(state.pathParameters['requiredBigIntField']!)!, - bigIntField: _$convertMapValue( - 'big-int-field', state.uri.queryParameters, BigInt.tryParse), - ); + requiredBigIntField: + BigInt.parse(state.pathParameters['requiredBigIntField']!)!, + bigIntField: _$convertMapValue( + '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(_self.requiredBigIntField.toString())}', - queryParams: { - if (_self.bigIntField != null) - 'big-int-field': _self.bigIntField!.toString(), - }, - ); + '/big-int-route/${Uri.encodeComponent(_self.requiredBigIntField.toString())}', + queryParams: { + if (_self.bigIntField != null) + 'big-int-field': _self.bigIntField!.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -129,30 +128,34 @@ mixin _$BigIntRoute on GoRouteData { mixin _$BoolRoute on GoRouteData { static BoolRoute _fromState(GoRouterState state) => BoolRoute( - requiredBoolField: - _$boolConverter(state.pathParameters['requiredBoolField']!)!, - boolField: _$convertMapValue( - 'bool-field', state.uri.queryParameters, _$boolConverter), - boolFieldWithDefaultValue: _$convertMapValue( - 'bool-field-with-default-value', - state.uri.queryParameters, - _$boolConverter) ?? - true, - ); + requiredBoolField: + _$boolConverter(state.pathParameters['requiredBoolField']!)!, + boolField: _$convertMapValue( + 'bool-field', + state.uri.queryParameters, + _$boolConverter, + ), + boolFieldWithDefaultValue: + _$convertMapValue( + 'bool-field-with-default-value', + state.uri.queryParameters, + _$boolConverter, + ) ?? + true, + ); BoolRoute get _self => this as BoolRoute; @override String get location => GoRouteData.$location( - '/bool-route/${Uri.encodeComponent(_self.requiredBoolField.toString())}', - queryParams: { - if (_self.boolField != null) - 'bool-field': _self.boolField!.toString(), - if (_self.boolFieldWithDefaultValue != true) - 'bool-field-with-default-value': - _self.boolFieldWithDefaultValue.toString(), - }, - ); + '/bool-route/${Uri.encodeComponent(_self.requiredBoolField.toString())}', + queryParams: { + if (_self.boolField != null) 'bool-field': _self.boolField!.toString(), + if (_self.boolFieldWithDefaultValue != true) + 'bool-field-with-default-value': + _self.boolFieldWithDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -170,22 +173,25 @@ mixin _$BoolRoute on GoRouteData { mixin _$DateTimeRoute on GoRouteData { static DateTimeRoute _fromState(GoRouterState state) => DateTimeRoute( - requiredDateTimeField: - DateTime.parse(state.pathParameters['requiredDateTimeField']!)!, - dateTimeField: _$convertMapValue( - 'date-time-field', state.uri.queryParameters, DateTime.tryParse), - ); + requiredDateTimeField: + DateTime.parse(state.pathParameters['requiredDateTimeField']!)!, + dateTimeField: _$convertMapValue( + '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(_self.requiredDateTimeField.toString())}', - queryParams: { - if (_self.dateTimeField != null) - 'date-time-field': _self.dateTimeField!.toString(), - }, - ); + '/date-time-route/${Uri.encodeComponent(_self.requiredDateTimeField.toString())}', + queryParams: { + if (_self.dateTimeField != null) + 'date-time-field': _self.dateTimeField!.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -203,30 +209,35 @@ mixin _$DateTimeRoute on GoRouteData { mixin _$DoubleRoute on GoRouteData { static DoubleRoute _fromState(GoRouterState state) => DoubleRoute( - requiredDoubleField: - double.parse(state.pathParameters['requiredDoubleField']!)!, - doubleField: _$convertMapValue( - 'double-field', state.uri.queryParameters, double.tryParse), - doubleFieldWithDefaultValue: _$convertMapValue( - 'double-field-with-default-value', - state.uri.queryParameters, - double.parse) ?? - 1.0, - ); + requiredDoubleField: + double.parse(state.pathParameters['requiredDoubleField']!)!, + doubleField: _$convertMapValue( + 'double-field', + state.uri.queryParameters, + double.tryParse, + ), + doubleFieldWithDefaultValue: + _$convertMapValue( + 'double-field-with-default-value', + state.uri.queryParameters, + double.parse, + ) ?? + 1.0, + ); DoubleRoute get _self => this as DoubleRoute; @override String get location => GoRouteData.$location( - '/double-route/${Uri.encodeComponent(_self.requiredDoubleField.toString())}', - queryParams: { - if (_self.doubleField != null) - 'double-field': _self.doubleField!.toString(), - if (_self.doubleFieldWithDefaultValue != 1.0) - 'double-field-with-default-value': - _self.doubleFieldWithDefaultValue.toString(), - }, - ); + '/double-route/${Uri.encodeComponent(_self.requiredDoubleField.toString())}', + queryParams: { + if (_self.doubleField != null) + 'double-field': _self.doubleField!.toString(), + if (_self.doubleFieldWithDefaultValue != 1.0) + 'double-field-with-default-value': + _self.doubleFieldWithDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -244,28 +255,33 @@ mixin _$DoubleRoute on GoRouteData { mixin _$IntRoute on GoRouteData { static IntRoute _fromState(GoRouterState state) => IntRoute( - requiredIntField: int.parse(state.pathParameters['requiredIntField']!)!, - intField: _$convertMapValue( - 'int-field', state.uri.queryParameters, int.tryParse), - intFieldWithDefaultValue: _$convertMapValue( - 'int-field-with-default-value', - state.uri.queryParameters, - int.parse) ?? - 1, - ); + requiredIntField: int.parse(state.pathParameters['requiredIntField']!)!, + intField: _$convertMapValue( + 'int-field', + state.uri.queryParameters, + int.tryParse, + ), + intFieldWithDefaultValue: + _$convertMapValue( + 'int-field-with-default-value', + state.uri.queryParameters, + int.parse, + ) ?? + 1, + ); IntRoute get _self => this as IntRoute; @override String get location => GoRouteData.$location( - '/int-route/${Uri.encodeComponent(_self.requiredIntField.toString())}', - queryParams: { - if (_self.intField != null) 'int-field': _self.intField!.toString(), - if (_self.intFieldWithDefaultValue != 1) - 'int-field-with-default-value': - _self.intFieldWithDefaultValue.toString(), - }, - ); + '/int-route/${Uri.encodeComponent(_self.requiredIntField.toString())}', + queryParams: { + 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); @@ -283,28 +299,33 @@ mixin _$IntRoute on GoRouteData { mixin _$NumRoute on GoRouteData { static NumRoute _fromState(GoRouterState state) => NumRoute( - requiredNumField: num.parse(state.pathParameters['requiredNumField']!)!, - numField: _$convertMapValue( - 'num-field', state.uri.queryParameters, num.tryParse), - numFieldWithDefaultValue: _$convertMapValue( - 'num-field-with-default-value', - state.uri.queryParameters, - num.parse) ?? - 1, - ); + requiredNumField: num.parse(state.pathParameters['requiredNumField']!)!, + numField: _$convertMapValue( + 'num-field', + state.uri.queryParameters, + num.tryParse, + ), + numFieldWithDefaultValue: + _$convertMapValue( + 'num-field-with-default-value', + state.uri.queryParameters, + num.parse, + ) ?? + 1, + ); NumRoute get _self => this as NumRoute; @override String get location => GoRouteData.$location( - '/num-route/${Uri.encodeComponent(_self.requiredNumField.toString())}', - queryParams: { - if (_self.numField != null) 'num-field': _self.numField!.toString(), - if (_self.numFieldWithDefaultValue != 1) - 'num-field-with-default-value': - _self.numFieldWithDefaultValue.toString(), - }, - ); + '/num-route/${Uri.encodeComponent(_self.requiredNumField.toString())}', + queryParams: { + 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); @@ -322,30 +343,37 @@ mixin _$NumRoute on GoRouteData { mixin _$EnumRoute on GoRouteData { static EnumRoute _fromState(GoRouterState state) => EnumRoute( - requiredEnumField: _$PersonDetailsEnumMap - ._$fromName(state.pathParameters['requiredEnumField']!)!, - enumField: _$convertMapValue('enum-field', state.uri.queryParameters, - _$PersonDetailsEnumMap._$fromName), - enumFieldWithDefaultValue: _$convertMapValue( - 'enum-field-with-default-value', - state.uri.queryParameters, - _$PersonDetailsEnumMap._$fromName) ?? - PersonDetails.favoriteFood, - ); + requiredEnumField: + _$PersonDetailsEnumMap._$fromName( + state.pathParameters['requiredEnumField']!, + )!, + enumField: _$convertMapValue( + 'enum-field', + state.uri.queryParameters, + _$PersonDetailsEnumMap._$fromName, + ), + enumFieldWithDefaultValue: + _$convertMapValue( + 'enum-field-with-default-value', + state.uri.queryParameters, + _$PersonDetailsEnumMap._$fromName, + ) ?? + PersonDetails.favoriteFood, + ); EnumRoute get _self => this as EnumRoute; @override String get location => GoRouteData.$location( - '/enum-route/${Uri.encodeComponent(_$PersonDetailsEnumMap[_self.requiredEnumField]!)}', - queryParams: { - if (_self.enumField != null) - 'enum-field': _$PersonDetailsEnumMap[_self.enumField!], - if (_self.enumFieldWithDefaultValue != PersonDetails.favoriteFood) - 'enum-field-with-default-value': - _$PersonDetailsEnumMap[_self.enumFieldWithDefaultValue], - }, - ); + '/enum-route/${Uri.encodeComponent(_$PersonDetailsEnumMap[_self.requiredEnumField]!)}', + queryParams: { + if (_self.enumField != null) + 'enum-field': _$PersonDetailsEnumMap[_self.enumField!], + if (_self.enumFieldWithDefaultValue != PersonDetails.favoriteFood) + 'enum-field-with-default-value': + _$PersonDetailsEnumMap[_self.enumFieldWithDefaultValue], + }, + ); @override void go(BuildContext context) => context.go(location); @@ -369,30 +397,37 @@ const _$PersonDetailsEnumMap = { mixin _$EnhancedEnumRoute on GoRouteData { static EnhancedEnumRoute _fromState(GoRouterState state) => EnhancedEnumRoute( - requiredEnumField: _$SportDetailsEnumMap - ._$fromName(state.pathParameters['requiredEnumField']!)!, - enumField: _$convertMapValue('enum-field', state.uri.queryParameters, - _$SportDetailsEnumMap._$fromName), - enumFieldWithDefaultValue: _$convertMapValue( - 'enum-field-with-default-value', - state.uri.queryParameters, - _$SportDetailsEnumMap._$fromName) ?? - SportDetails.football, - ); + requiredEnumField: + _$SportDetailsEnumMap._$fromName( + state.pathParameters['requiredEnumField']!, + )!, + enumField: _$convertMapValue( + 'enum-field', + state.uri.queryParameters, + _$SportDetailsEnumMap._$fromName, + ), + enumFieldWithDefaultValue: + _$convertMapValue( + 'enum-field-with-default-value', + state.uri.queryParameters, + _$SportDetailsEnumMap._$fromName, + ) ?? + SportDetails.football, + ); EnhancedEnumRoute get _self => this as EnhancedEnumRoute; @override String get location => GoRouteData.$location( - '/enhanced-enum-route/${Uri.encodeComponent(_$SportDetailsEnumMap[_self.requiredEnumField]!)}', - queryParams: { - if (_self.enumField != null) - 'enum-field': _$SportDetailsEnumMap[_self.enumField!], - if (_self.enumFieldWithDefaultValue != SportDetails.football) - 'enum-field-with-default-value': - _$SportDetailsEnumMap[_self.enumFieldWithDefaultValue], - }, - ); + '/enhanced-enum-route/${Uri.encodeComponent(_$SportDetailsEnumMap[_self.requiredEnumField]!)}', + queryParams: { + if (_self.enumField != null) + 'enum-field': _$SportDetailsEnumMap[_self.enumField!], + if (_self.enumFieldWithDefaultValue != SportDetails.football) + 'enum-field-with-default-value': + _$SportDetailsEnumMap[_self.enumFieldWithDefaultValue], + }, + ); @override void go(BuildContext context) => context.go(location); @@ -417,25 +452,24 @@ const _$SportDetailsEnumMap = { mixin _$StringRoute on GoRouteData { static StringRoute _fromState(GoRouterState state) => StringRoute( - requiredStringField: state.pathParameters['requiredStringField']!, - stringField: state.uri.queryParameters['string-field'], - stringFieldWithDefaultValue: - state.uri.queryParameters['string-field-with-default-value'] ?? - 'defaultValue', - ); + requiredStringField: state.pathParameters['requiredStringField']!, + stringField: state.uri.queryParameters['string-field'], + stringFieldWithDefaultValue: + state.uri.queryParameters['string-field-with-default-value'] ?? + 'defaultValue', + ); StringRoute get _self => this as StringRoute; @override String get location => GoRouteData.$location( - '/string-route/${Uri.encodeComponent(_self.requiredStringField)}', - queryParams: { - if (_self.stringField != null) 'string-field': _self.stringField, - if (_self.stringFieldWithDefaultValue != 'defaultValue') - 'string-field-with-default-value': - _self.stringFieldWithDefaultValue, - }, - ); + '/string-route/${Uri.encodeComponent(_self.requiredStringField)}', + queryParams: { + 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); @@ -453,20 +487,23 @@ mixin _$StringRoute on GoRouteData { 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), - ); + 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(_self.requiredUriField.toString())}', - queryParams: { - if (_self.uriField != null) 'uri-field': _self.uriField!.toString(), - }, - ); + '/uri-route/${Uri.encodeComponent(_self.requiredUriField.toString())}', + queryParams: { + if (_self.uriField != null) 'uri-field': _self.uriField!.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -484,150 +521,178 @@ mixin _$UriRoute on GoRouteData { mixin _$IterableRoute on GoRouteData { static IterableRoute _fromState(GoRouterState state) => IterableRoute( - intIterableField: (state.uri.queryParametersAll['int-iterable-field'] - ?.map(int.parse) - .cast() as Iterable?), - doubleIterableField: (state - .uri.queryParametersAll['double-iterable-field'] - ?.map(double.parse) - .cast() as Iterable?), - stringIterableField: (state - .uri.queryParametersAll['string-iterable-field'] - ?.map((e) => e)), - boolIterableField: (state.uri.queryParametersAll['bool-iterable-field'] - ?.map(_$boolConverter) - .cast() as Iterable?), - enumIterableField: (state.uri.queryParametersAll['enum-iterable-field'] - ?.map(_$SportDetailsEnumMap._$fromName) - .cast() as Iterable?), - enumOnlyInIterableField: (state - .uri.queryParametersAll['enum-only-in-iterable-field'] - ?.map(_$CookingRecipeEnumMap._$fromName) - .cast() as Iterable?), - intListField: (state.uri.queryParametersAll['int-list-field'] + intIterableField: + (state.uri.queryParametersAll['int-iterable-field'] ?.map(int.parse) .cast() - ?.toList() as List?) - ?.toList(), - doubleListField: (state.uri.queryParametersAll['double-list-field'] + as Iterable?), + doubleIterableField: + (state.uri.queryParametersAll['double-iterable-field'] ?.map(double.parse) .cast() - ?.toList() as List?) - ?.toList(), - stringListField: (state.uri.queryParametersAll['string-list-field'] - ?.map((e) => e))?.toList(), - boolListField: (state.uri.queryParametersAll['bool-list-field'] + as Iterable?), + stringIterableField: (state.uri.queryParametersAll['string-iterable-field'] + ?.map((e) => e)), + boolIterableField: + (state.uri.queryParametersAll['bool-iterable-field'] ?.map(_$boolConverter) .cast() - ?.toList() as List?) - ?.toList(), - enumListField: (state.uri.queryParametersAll['enum-list-field'] + as Iterable?), + enumIterableField: + (state.uri.queryParametersAll['enum-iterable-field'] ?.map(_$SportDetailsEnumMap._$fromName) .cast() - ?.toList() as List?) - ?.toList(), - enumOnlyInListField: (state - .uri.queryParametersAll['enum-only-in-list-field'] + as Iterable?), + enumOnlyInIterableField: + (state.uri.queryParametersAll['enum-only-in-iterable-field'] ?.map(_$CookingRecipeEnumMap._$fromName) .cast() - ?.toList() as List?) + as Iterable?), + intListField: + (state.uri.queryParametersAll['int-list-field'] + ?.map(int.parse) + .cast() + ?.toList() + as List?) ?.toList(), - intSetField: (state.uri.queryParametersAll['int-set-field'] - ?.map(int.parse) - .cast() - ?.toSet() as Set?) + doubleListField: + (state.uri.queryParametersAll['double-list-field'] + ?.map(double.parse) + .cast() + ?.toList() + as List?) + ?.toList(), + stringListField: + (state.uri.queryParametersAll['string-list-field']?.map( + (e) => e, + ))?.toList(), + boolListField: + (state.uri.queryParametersAll['bool-list-field'] + ?.map(_$boolConverter) + .cast() + ?.toList() + as List?) + ?.toList(), + enumListField: + (state.uri.queryParametersAll['enum-list-field'] + ?.map(_$SportDetailsEnumMap._$fromName) + .cast() + ?.toList() + as List?) + ?.toList(), + enumOnlyInListField: + (state.uri.queryParametersAll['enum-only-in-list-field'] + ?.map(_$CookingRecipeEnumMap._$fromName) + .cast() + ?.toList() + as List?) + ?.toList(), + intSetField: + (state.uri.queryParametersAll['int-set-field'] + ?.map(int.parse) + .cast() + ?.toSet() + as Set?) ?.toSet(), - doubleSetField: (state.uri.queryParametersAll['double-set-field'] - ?.map(double.parse) - .cast() - ?.toSet() as Set?) + doubleSetField: + (state.uri.queryParametersAll['double-set-field'] + ?.map(double.parse) + .cast() + ?.toSet() + as Set?) ?.toSet(), - stringSetField: (state.uri.queryParametersAll['string-set-field'] - ?.map((e) => e))?.toSet(), - boolSetField: (state.uri.queryParametersAll['bool-set-field'] - ?.map(_$boolConverter) - .cast() - ?.toSet() as Set?) + stringSetField: + (state.uri.queryParametersAll['string-set-field']?.map( + (e) => e, + ))?.toSet(), + boolSetField: + (state.uri.queryParametersAll['bool-set-field'] + ?.map(_$boolConverter) + .cast() + ?.toSet() + as Set?) ?.toSet(), - enumSetField: (state.uri.queryParametersAll['enum-set-field'] - ?.map(_$SportDetailsEnumMap._$fromName) - .cast() - ?.toSet() as Set?) + enumSetField: + (state.uri.queryParametersAll['enum-set-field'] + ?.map(_$SportDetailsEnumMap._$fromName) + .cast() + ?.toSet() + as Set?) ?.toSet(), - enumOnlyInSetField: (state - .uri.queryParametersAll['enum-only-in-set-field'] - ?.map(_$CookingRecipeEnumMap._$fromName) - .cast() - ?.toSet() as Set?) + enumOnlyInSetField: + (state.uri.queryParametersAll['enum-only-in-set-field'] + ?.map(_$CookingRecipeEnumMap._$fromName) + .cast() + ?.toSet() + as Set?) ?.toSet(), - ); + ); IterableRoute get _self => this as IterableRoute; @override String get location => GoRouteData.$location( - '/iterable-route', - queryParams: { - if (_self.intIterableField != null) - 'int-iterable-field': - _self.intIterableField?.map((e) => e.toString()).toList(), - if (_self.doubleIterableField != null) - 'double-iterable-field': - _self.doubleIterableField?.map((e) => e.toString()).toList(), - if (_self.stringIterableField != null) - 'string-iterable-field': - _self.stringIterableField?.map((e) => e).toList(), - if (_self.boolIterableField != null) - 'bool-iterable-field': - _self.boolIterableField?.map((e) => e.toString()).toList(), - if (_self.enumIterableField != null) - 'enum-iterable-field': _self.enumIterableField + '/iterable-route', + queryParams: { + if (_self.intIterableField != null) + 'int-iterable-field': + _self.intIterableField?.map((e) => e.toString()).toList(), + if (_self.doubleIterableField != null) + 'double-iterable-field': + _self.doubleIterableField?.map((e) => e.toString()).toList(), + if (_self.stringIterableField != null) + 'string-iterable-field': + _self.stringIterableField?.map((e) => e).toList(), + if (_self.boolIterableField != null) + 'bool-iterable-field': + _self.boolIterableField?.map((e) => e.toString()).toList(), + if (_self.enumIterableField != null) + 'enum-iterable-field': + _self.enumIterableField ?.map((e) => _$SportDetailsEnumMap[e]) .toList(), - if (_self.enumOnlyInIterableField != null) - 'enum-only-in-iterable-field': _self.enumOnlyInIterableField + if (_self.enumOnlyInIterableField != null) + 'enum-only-in-iterable-field': + _self.enumOnlyInIterableField ?.map((e) => _$CookingRecipeEnumMap[e]) .toList(), - if (_self.intListField != null) - 'int-list-field': - _self.intListField?.map((e) => e.toString()).toList(), - if (_self.doubleListField != null) - 'double-list-field': - _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 + if (_self.intListField != null) + 'int-list-field': _self.intListField?.map((e) => e.toString()).toList(), + if (_self.doubleListField != null) + 'double-list-field': + _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 (_self.intSetField != null) - 'int-set-field': - _self.intSetField?.map((e) => e.toString()).toList(), - if (_self.doubleSetField != null) - 'double-set-field': - _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 + if (_self.intSetField != null) + 'int-set-field': _self.intSetField?.map((e) => e.toString()).toList(), + if (_self.doubleSetField != null) + 'double-set-field': + _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); @@ -652,79 +717,107 @@ const _$CookingRecipeEnumMap = { mixin _$IterableRouteWithDefaultValues on GoRouteData { static IterableRouteWithDefaultValues _fromState(GoRouterState state) => IterableRouteWithDefaultValues( - intIterableField: (state.uri.queryParametersAll['int-iterable-field'] - ?.map(int.parse) - .cast() as Iterable?) ?? + intIterableField: + (state.uri.queryParametersAll['int-iterable-field'] + ?.map(int.parse) + .cast() + as Iterable?) ?? const [0], - doubleIterableField: (state - .uri.queryParametersAll['double-iterable-field'] - ?.map(double.parse) - .cast() as Iterable?) ?? + doubleIterableField: + (state.uri.queryParametersAll['double-iterable-field'] + ?.map(double.parse) + .cast() + as Iterable?) ?? const [0, 1, 2], - stringIterableField: (state - .uri.queryParametersAll['string-iterable-field'] - ?.map((e) => e)) ?? + stringIterableField: + (state.uri.queryParametersAll['string-iterable-field']?.map( + (e) => e, + )) ?? const ['defaultValue'], - boolIterableField: (state.uri.queryParametersAll['bool-iterable-field'] - ?.map(_$boolConverter) - .cast() as Iterable?) ?? + boolIterableField: + (state.uri.queryParametersAll['bool-iterable-field'] + ?.map(_$boolConverter) + .cast() + as Iterable?) ?? const [false], - enumIterableField: (state.uri.queryParametersAll['enum-iterable-field'] - ?.map(_$SportDetailsEnumMap._$fromName) - .cast() as Iterable?) ?? + enumIterableField: + (state.uri.queryParametersAll['enum-iterable-field'] + ?.map(_$SportDetailsEnumMap._$fromName) + .cast() + as Iterable?) ?? const [SportDetails.tennis, SportDetails.hockey], - intListField: (state.uri.queryParametersAll['int-list-field'] - ?.map(int.parse) - .cast() - ?.toList() as List?) + intListField: + (state.uri.queryParametersAll['int-list-field'] + ?.map(int.parse) + .cast() + ?.toList() + as List?) ?.toList() ?? const [0], - doubleListField: (state.uri.queryParametersAll['double-list-field'] - ?.map(double.parse) - .cast() - ?.toList() as List?) + doubleListField: + (state.uri.queryParametersAll['double-list-field'] + ?.map(double.parse) + .cast() + ?.toList() + as List?) ?.toList() ?? const [1, 2, 3], - stringListField: (state.uri.queryParametersAll['string-list-field'] - ?.map((e) => e))?.toList() ?? + stringListField: + (state.uri.queryParametersAll['string-list-field']?.map( + (e) => e, + ))?.toList() ?? const ['defaultValue0', 'defaultValue1'], - boolListField: (state.uri.queryParametersAll['bool-list-field'] - ?.map(_$boolConverter) - .cast() - ?.toList() as List?) + boolListField: + (state.uri.queryParametersAll['bool-list-field'] + ?.map(_$boolConverter) + .cast() + ?.toList() + as List?) ?.toList() ?? const [true], - enumListField: (state.uri.queryParametersAll['enum-list-field'] - ?.map(_$SportDetailsEnumMap._$fromName) - .cast() - ?.toList() as List?) + enumListField: + (state.uri.queryParametersAll['enum-list-field'] + ?.map(_$SportDetailsEnumMap._$fromName) + .cast() + ?.toList() + as List?) ?.toList() ?? const [SportDetails.football], - intSetField: (state.uri.queryParametersAll['int-set-field'] - ?.map(int.parse) - .cast() - ?.toSet() as Set?) + intSetField: + (state.uri.queryParametersAll['int-set-field'] + ?.map(int.parse) + .cast() + ?.toSet() + as Set?) ?.toSet() ?? const {0, 1}, - doubleSetField: (state.uri.queryParametersAll['double-set-field'] - ?.map(double.parse) - .cast() - ?.toSet() as Set?) + doubleSetField: + (state.uri.queryParametersAll['double-set-field'] + ?.map(double.parse) + .cast() + ?.toSet() + as Set?) ?.toSet() ?? const {}, - stringSetField: (state.uri.queryParametersAll['string-set-field'] - ?.map((e) => e))?.toSet() ?? + stringSetField: + (state.uri.queryParametersAll['string-set-field']?.map( + (e) => e, + ))?.toSet() ?? const {'defaultValue'}, - boolSetField: (state.uri.queryParametersAll['bool-set-field'] - ?.map(_$boolConverter) - .cast() - ?.toSet() as Set?) + boolSetField: + (state.uri.queryParametersAll['bool-set-field'] + ?.map(_$boolConverter) + .cast() + ?.toSet() + as Set?) ?.toSet() ?? const {true, false}, - enumSetField: (state.uri.queryParametersAll['enum-set-field'] - ?.map(_$SportDetailsEnumMap._$fromName) - .cast() - ?.toSet() as Set?) + enumSetField: + (state.uri.queryParametersAll['enum-set-field'] + ?.map(_$SportDetailsEnumMap._$fromName) + .cast() + ?.toSet() + as Set?) ?.toSet() ?? const {SportDetails.hockey}, ); @@ -734,63 +827,66 @@ mixin _$IterableRouteWithDefaultValues on GoRouteData { @override String get location => GoRouteData.$location( - '/iterable-route-with-default-values', - queryParams: { - if (!_$iterablesEqual(_self.intIterableField, const [0])) - 'int-iterable-field': - _self.intIterableField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual( - _self.doubleIterableField, const [0, 1, 2])) - 'double-iterable-field': - _self.doubleIterableField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual( - _self.stringIterableField, const ['defaultValue'])) - 'string-iterable-field': - _self.stringIterableField.map((e) => e).toList(), - if (!_$iterablesEqual(_self.boolIterableField, const [false])) - 'bool-iterable-field': - _self.boolIterableField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(_self.enumIterableField, - const [SportDetails.tennis, SportDetails.hockey])) - 'enum-iterable-field': _self.enumIterableField + '/iterable-route-with-default-values', + queryParams: { + if (!_$iterablesEqual(_self.intIterableField, const [0])) + 'int-iterable-field': + _self.intIterableField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.doubleIterableField, const [0, 1, 2])) + 'double-iterable-field': + _self.doubleIterableField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.stringIterableField, const [ + 'defaultValue', + ])) + 'string-iterable-field': + _self.stringIterableField.map((e) => e).toList(), + if (!_$iterablesEqual(_self.boolIterableField, const [false])) + 'bool-iterable-field': + _self.boolIterableField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.enumIterableField, const [ + SportDetails.tennis, + SportDetails.hockey, + ])) + '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': - _self.doubleListField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(_self.stringListField, - const ['defaultValue0', 'defaultValue1'])) - '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( - _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': - _self.doubleSetField.map((e) => e.toString()).toList(), - if (!_$iterablesEqual( - _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(), - }, - ); + 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': + _self.doubleListField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.stringListField, const [ + 'defaultValue0', + 'defaultValue1', + ])) + '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(_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': + _self.doubleSetField.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_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); 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 65d82e8790f..fb873a81a6d 100644 --- a/packages/go_router_builder/example/lib/case_sensitive_example.dart +++ b/packages/go_router_builder/example/lib/case_sensitive_example.dart @@ -15,9 +15,8 @@ class CaseSensitivityApp extends StatelessWidget { CaseSensitivityApp({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router); final GoRouter _router = GoRouter( initialLocation: '/case-sensitive', @@ -25,16 +24,13 @@ class CaseSensitivityApp extends StatelessWidget { ); } -@TypedGoRoute( - path: '/case-sensitive', -) +@TypedGoRoute(path: '/case-sensitive') class CaseSensitiveRoute extends GoRouteData with _$CaseSensitiveRoute { const CaseSensitiveRoute(); @override - Widget build(BuildContext context, GoRouterState state) => const Screen( - title: 'Case Sensitive', - ); + Widget build(BuildContext context, GoRouterState state) => + const Screen(title: 'Case Sensitive'); } @TypedGoRoute( @@ -45,9 +41,8 @@ class NotCaseSensitiveRoute extends GoRouteData with _$NotCaseSensitiveRoute { const NotCaseSensitiveRoute(); @override - Widget build(BuildContext context, GoRouterState state) => const Screen( - title: 'Not Case Sensitive', - ); + Widget build(BuildContext context, GoRouterState state) => + const Screen(title: 'Not Case Sensitive'); } class Screen extends StatelessWidget { @@ -56,20 +51,18 @@ class Screen extends StatelessWidget { final String title; @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar( - title: Text(title), + appBar: AppBar(title: Text(title)), + body: ListView( + children: [ + ListTile( + title: const Text('Case Sensitive'), + onTap: () => context.go('/case-sensitive'), ), - body: ListView( - children: [ - ListTile( - title: const Text('Case Sensitive'), - onTap: () => context.go('/case-sensitive'), - ), - ListTile( - title: const Text('Not Case Sensitive'), - onTap: () => context.go('/not-case-sensitive'), - ), - ], + ListTile( + title: const Text('Not Case Sensitive'), + onTap: () => context.go('/not-case-sensitive'), ), - ); + ], + ), + ); } 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 3c6a5b84e31..6f3f6e6843e 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 @@ -8,24 +8,19 @@ part of 'case_sensitive_example.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $caseSensitiveRoute, - $notCaseSensitiveRoute, - ]; +List get $appRoutes => [$caseSensitiveRoute, $notCaseSensitiveRoute]; RouteBase get $caseSensitiveRoute => GoRouteData.$route( - path: '/case-sensitive', - factory: _$CaseSensitiveRoute._fromState, - ); + path: '/case-sensitive', + factory: _$CaseSensitiveRoute._fromState, +); mixin _$CaseSensitiveRoute on GoRouteData { static CaseSensitiveRoute _fromState(GoRouterState state) => const CaseSensitiveRoute(); @override - String get location => GoRouteData.$location( - '/case-sensitive', - ); + String get location => GoRouteData.$location('/case-sensitive'); @override void go(BuildContext context) => context.go(location); @@ -42,19 +37,17 @@ mixin _$CaseSensitiveRoute on GoRouteData { } RouteBase get $notCaseSensitiveRoute => GoRouteData.$route( - path: '/not-case-sensitive', - caseSensitive: false, - factory: _$NotCaseSensitiveRoute._fromState, - ); + path: '/not-case-sensitive', + caseSensitive: false, + factory: _$NotCaseSensitiveRoute._fromState, +); mixin _$NotCaseSensitiveRoute on GoRouteData { static NotCaseSensitiveRoute _fromState(GoRouterState state) => const NotCaseSensitiveRoute(); @override - String get location => GoRouteData.$location( - '/not-case-sensitive', - ); + String get location => GoRouteData.$location('/not-case-sensitive'); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/example/lib/extra_example.dart b/packages/go_router_builder/example/lib/extra_example.dart index 5f281cd4e46..bccc01a8518 100644 --- a/packages/go_router_builder/example/lib/extra_example.dart +++ b/packages/go_router_builder/example/lib/extra_example.dart @@ -21,9 +21,7 @@ class App extends StatelessWidget { @override Widget build(BuildContext context) { - return MaterialApp.router( - routerConfig: _router, - ); + return MaterialApp.router(routerConfig: _router); } } @@ -103,13 +101,13 @@ class Splash extends StatelessWidget { children: [ const Placeholder(), ElevatedButton( - onPressed: () => - const RequiredExtraRoute($extra: Extra(1)).go(context), + onPressed: + () => const RequiredExtraRoute($extra: Extra(1)).go(context), child: const Text('Required Extra'), ), ElevatedButton( - onPressed: () => - const OptionalExtraRoute($extra: Extra(2)).go(context), + onPressed: + () => const OptionalExtraRoute($extra: Extra(2)).go(context), child: const Text('Optional Extra'), ), ElevatedButton( 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 1161326b103..b4591664cca 100644 --- a/packages/go_router_builder/example/lib/extra_example.g.dart +++ b/packages/go_router_builder/example/lib/extra_example.g.dart @@ -9,28 +9,24 @@ part of 'extra_example.dart'; // ************************************************************************** List get $appRoutes => [ - $requiredExtraRoute, - $optionalExtraRoute, - $splashRoute, - ]; + $requiredExtraRoute, + $optionalExtraRoute, + $splashRoute, +]; RouteBase get $requiredExtraRoute => GoRouteData.$route( - path: '/requiredExtra', - factory: _$RequiredExtraRoute._fromState, - ); + path: '/requiredExtra', + factory: _$RequiredExtraRoute._fromState, +); mixin _$RequiredExtraRoute on GoRouteData { static RequiredExtraRoute _fromState(GoRouterState state) => - RequiredExtraRoute( - $extra: state.extra as Extra, - ); + RequiredExtraRoute($extra: state.extra as Extra); RequiredExtraRoute get _self => this as RequiredExtraRoute; @override - String get location => GoRouteData.$location( - '/requiredExtra', - ); + String get location => GoRouteData.$location('/requiredExtra'); @override void go(BuildContext context) => context.go(location, extra: _self.$extra); @@ -49,22 +45,18 @@ mixin _$RequiredExtraRoute on GoRouteData { } RouteBase get $optionalExtraRoute => GoRouteData.$route( - path: '/optionalExtra', - factory: _$OptionalExtraRoute._fromState, - ); + path: '/optionalExtra', + factory: _$OptionalExtraRoute._fromState, +); mixin _$OptionalExtraRoute on GoRouteData { static OptionalExtraRoute _fromState(GoRouterState state) => - OptionalExtraRoute( - $extra: state.extra as Extra?, - ); + OptionalExtraRoute($extra: state.extra as Extra?); OptionalExtraRoute get _self => this as OptionalExtraRoute; @override - String get location => GoRouteData.$location( - '/optionalExtra', - ); + String get location => GoRouteData.$location('/optionalExtra'); @override void go(BuildContext context) => context.go(location, extra: _self.$extra); @@ -82,18 +74,14 @@ mixin _$OptionalExtraRoute on GoRouteData { context.replace(location, extra: _self.$extra); } -RouteBase get $splashRoute => GoRouteData.$route( - path: '/splash', - factory: _$SplashRoute._fromState, - ); +RouteBase get $splashRoute => + GoRouteData.$route(path: '/splash', factory: _$SplashRoute._fromState); mixin _$SplashRoute on GoRouteData { static SplashRoute _fromState(GoRouterState state) => const SplashRoute(); @override - String get location => GoRouteData.$location( - '/splash', - ); + String get location => GoRouteData.$location('/splash'); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart index 38136b17a9d..6ecb5778877 100644 --- a/packages/go_router_builder/example/lib/main.dart +++ b/packages/go_router_builder/example/lib/main.dart @@ -24,13 +24,13 @@ class App extends StatelessWidget { @override Widget build(BuildContext context) => ChangeNotifierProvider.value( - value: loginInfo, - child: MaterialApp.router( - routerConfig: _router, - title: title, - debugShowCheckedModeBanner: false, - ), - ); + value: loginInfo, + child: MaterialApp.router( + routerConfig: _router, + title: title, + debugShowCheckedModeBanner: false, + ), + ); late final GoRouter _router = GoRouter( debugLogDiagnostics: true, @@ -87,9 +87,7 @@ class HomeRoute extends GoRouteData with _$HomeRoute { Widget build(BuildContext context, GoRouterState state) => const HomeScreen(); } -@TypedGoRoute( - path: '/login', -) +@TypedGoRoute(path: '/login') class LoginRoute extends GoRouteData with _$LoginRoute { const LoginRoute({this.fromPage}); @@ -156,9 +154,8 @@ class FamilyCountRoute extends GoRouteData with _$FamilyCountRoute { final int count; @override - Widget build(BuildContext context, GoRouterState state) => FamilyCountScreen( - count: count, - ); + Widget build(BuildContext context, GoRouterState state) => + FamilyCountScreen(count: count); } class HomeScreen extends StatelessWidget { @@ -185,20 +182,20 @@ class HomeScreen extends StatelessWidget { value: '2', child: const Text('Push w/ return value'), onTap: () async { - unawaited(FamilyCountRoute(familyData.length) - .push(context) - .then((int? value) { - if (!context.mounted) { - return; - } - if (value != null) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text('Age was: $value'), - ), - ); - } - })); + unawaited( + FamilyCountRoute( + familyData.length, + ).push(context).then((int? value) { + if (!context.mounted) { + return; + } + if (value != null) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Age was: $value')), + ); + } + }), + ); }, ), PopupMenuItem( @@ -217,7 +214,7 @@ class HomeScreen extends StatelessWidget { ListTile( title: Text(f.name), onTap: () => FamilyRoute(f.id).go(context), - ) + ), ], ), ); @@ -230,17 +227,17 @@ class FamilyScreen extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: Text(family.name)), - body: ListView( - children: [ - for (final Person p in family.people) - ListTile( - title: Text(p.name), - onTap: () => PersonRoute(family.id, p.id).go(context), - ), - ], - ), - ); + appBar: AppBar(title: Text(family.name)), + body: ListView( + children: [ + for (final Person p in family.people) + ListTile( + title: Text(p.name), + onTap: () => PersonRoute(family.id, p.id).go(context), + ), + ], + ), + ); } class PersonScreen extends StatelessWidget { @@ -253,34 +250,38 @@ class PersonScreen extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: Text(person.name)), - body: ListView( - children: [ - ListTile( - title: Text( - '${person.name} ${family.name} is ${person.age} years old'), - ), - for (final MapEntry entry - in person.details.entries) - ListTile( - title: Text( - '${entry.key.name} - ${entry.value}', - ), - trailing: OutlinedButton( - onPressed: () => PersonDetailsRoute( + appBar: AppBar(title: Text(person.name)), + body: ListView( + children: [ + ListTile( + title: Text( + '${person.name} ${family.name} is ${person.age} years old', + ), + ), + for (final MapEntry entry + in person.details.entries) + ListTile( + title: Text('${entry.key.name} - ${entry.value}'), + trailing: OutlinedButton( + onPressed: + () => PersonDetailsRoute( family.id, person.id, entry.key, $extra: ++_extraClickCount, ).go(context), - child: const Text('With extra...'), - ), - onTap: () => PersonDetailsRoute(family.id, person.id, entry.key) - .go(context), - ) - ], - ), - ); + child: const Text('With extra...'), + ), + onTap: + () => PersonDetailsRoute( + family.id, + person.id, + entry.key, + ).go(context), + ), + ], + ), + ); } class PersonDetailsPage extends StatelessWidget { @@ -299,21 +300,20 @@ class PersonDetailsPage extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: Text(person.name)), - body: ListView( - children: [ - ListTile( - title: Text( - '${person.name} ${family.name}: ' - '$detailsKey - ${person.details[detailsKey]}', - ), - ), - if (extra == null) const ListTile(title: Text('No extra click!')), - if (extra != null) - ListTile(title: Text('Extra click count: $extra')), - ], + appBar: AppBar(title: Text(person.name)), + body: ListView( + children: [ + ListTile( + title: Text( + '${person.name} ${family.name}: ' + '$detailsKey - ${person.details[detailsKey]}', + ), ), - ); + if (extra == null) const ListTile(title: Text('No extra click!')), + if (extra != null) ListTile(title: Text('Extra click count: $extra')), + ], + ), + ); } class FamilyCountScreen extends StatelessWidget { @@ -323,26 +323,26 @@ class FamilyCountScreen extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: const Text('Family Count')), - body: Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Center( - child: Text( - 'There are $count families', - style: Theme.of(context).textTheme.headlineSmall, - ), - ), - ElevatedButton( - onPressed: () => context.pop(count), - child: Text('Pop with return value $count'), - ), - ], + appBar: AppBar(title: const Text('Family Count')), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Center( + child: Text( + 'There are $count families', + style: Theme.of(context).textTheme.headlineSmall, + ), ), - ), - ); + ElevatedButton( + onPressed: () => context.pop(count), + child: Text('Pop with return value $count'), + ), + ], + ), + ), + ); } class LoginScreen extends StatelessWidget { @@ -351,25 +351,25 @@ class LoginScreen extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: const Text(App.title)), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - ElevatedButton( - onPressed: () { - // log a user in, letting all the listeners know - context.read().login('test-user'); - - // if there's a deep link, go there - if (from != null) { - context.go(from!); - } - }, - child: const Text('Login'), - ), - ], + appBar: AppBar(title: const Text(App.title)), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + onPressed: () { + // log a user in, letting all the listeners know + context.read().login('test-user'); + + // if there's a deep link, go there + if (from != null) { + context.go(from!); + } + }, + child: const Text('Login'), ), - ), - ); + ], + ), + ), + ); } diff --git a/packages/go_router_builder/example/lib/main.g.dart b/packages/go_router_builder/example/lib/main.g.dart index f631d241cc0..99786802ebf 100644 --- a/packages/go_router_builder/example/lib/main.g.dart +++ b/packages/go_router_builder/example/lib/main.g.dart @@ -8,45 +8,40 @@ part of 'main.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $homeRoute, - $loginRoute, - ]; +List get $appRoutes => [$homeRoute, $loginRoute]; RouteBase get $homeRoute => GoRouteData.$route( - path: '/', - factory: _$HomeRoute._fromState, + path: '/', + factory: _$HomeRoute._fromState, + routes: [ + GoRouteData.$route( + path: 'family/:fid', + factory: _$FamilyRoute._fromState, routes: [ GoRouteData.$route( - path: 'family/:fid', - factory: _$FamilyRoute._fromState, + path: 'person/:pid', + factory: _$PersonRoute._fromState, routes: [ GoRouteData.$route( - path: 'person/:pid', - factory: _$PersonRoute._fromState, - routes: [ - GoRouteData.$route( - path: 'details/:details', - factory: _$PersonDetailsRoute._fromState, - ), - ], + path: 'details/:details', + factory: _$PersonDetailsRoute._fromState, ), ], ), - GoRouteData.$route( - path: 'family-count/:count', - factory: _$FamilyCountRoute._fromState, - ), ], - ); + ), + GoRouteData.$route( + path: 'family-count/:count', + factory: _$FamilyCountRoute._fromState, + ), + ], +); mixin _$HomeRoute on GoRouteData { static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); @override - String get location => GoRouteData.$location( - '/', - ); + String get location => GoRouteData.$location('/'); @override void go(BuildContext context) => context.go(location); @@ -63,16 +58,14 @@ mixin _$HomeRoute on GoRouteData { } mixin _$FamilyRoute on GoRouteData { - static FamilyRoute _fromState(GoRouterState state) => FamilyRoute( - state.pathParameters['fid']!, - ); + static FamilyRoute _fromState(GoRouterState state) => + FamilyRoute(state.pathParameters['fid']!); FamilyRoute get _self => this as FamilyRoute; @override - String get location => GoRouteData.$location( - '/family/${Uri.encodeComponent(_self.fid)}', - ); + String get location => + GoRouteData.$location('/family/${Uri.encodeComponent(_self.fid)}'); @override void go(BuildContext context) => context.go(location); @@ -90,16 +83,16 @@ mixin _$FamilyRoute on GoRouteData { mixin _$PersonRoute on GoRouteData { static PersonRoute _fromState(GoRouterState state) => PersonRoute( - state.pathParameters['fid']!, - int.parse(state.pathParameters['pid']!)!, - ); + state.pathParameters['fid']!, + int.parse(state.pathParameters['pid']!)!, + ); PersonRoute get _self => this as PersonRoute; @override String get location => GoRouteData.$location( - '/family/${Uri.encodeComponent(_self.fid)}/person/${Uri.encodeComponent(_self.pid.toString())}', - ); + '/family/${Uri.encodeComponent(_self.fid)}/person/${Uri.encodeComponent(_self.pid.toString())}', + ); @override void go(BuildContext context) => context.go(location); @@ -128,8 +121,8 @@ mixin _$PersonDetailsRoute on GoRouteData { @override String get location => GoRouteData.$location( - '/family/${Uri.encodeComponent(_self.fid)}/person/${Uri.encodeComponent(_self.pid.toString())}/details/${Uri.encodeComponent(_$PersonDetailsEnumMap[_self.details]!)}', - ); + '/family/${Uri.encodeComponent(_self.fid)}/person/${Uri.encodeComponent(_self.pid.toString())}/details/${Uri.encodeComponent(_$PersonDetailsEnumMap[_self.details]!)}', + ); @override void go(BuildContext context) => context.go(location, extra: _self.$extra); @@ -154,16 +147,15 @@ const _$PersonDetailsEnumMap = { }; mixin _$FamilyCountRoute on GoRouteData { - static FamilyCountRoute _fromState(GoRouterState state) => FamilyCountRoute( - int.parse(state.pathParameters['count']!)!, - ); + 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(_self.count.toString())}', - ); + '/family-count/${Uri.encodeComponent(_self.count.toString())}', + ); @override void go(BuildContext context) => context.go(location); @@ -184,25 +176,20 @@ extension on Map { entries.where((element) => element.value == value).firstOrNull?.key; } -RouteBase get $loginRoute => GoRouteData.$route( - path: '/login', - factory: _$LoginRoute._fromState, - ); +RouteBase get $loginRoute => + GoRouteData.$route(path: '/login', factory: _$LoginRoute._fromState); mixin _$LoginRoute on GoRouteData { - static LoginRoute _fromState(GoRouterState state) => LoginRoute( - fromPage: state.uri.queryParameters['from-page'], - ); + 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 (_self.fromPage != null) 'from-page': _self.fromPage, - }, - ); + '/login', + queryParams: {if (_self.fromPage != null) 'from-page': _self.fromPage}, + ); @override void go(BuildContext context) => context.go(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 bbd8fea19bb..57698c4282b 100644 --- a/packages/go_router_builder/example/lib/on_exit_example.dart +++ b/packages/go_router_builder/example/lib/on_exit_example.dart @@ -15,10 +15,8 @@ class App extends StatelessWidget { App({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - title: _appTitle, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router, title: _appTitle); final GoRouter _router = GoRouter(routes: $appRoutes); } @@ -26,7 +24,7 @@ class App extends StatelessWidget { @TypedGoRoute( path: '/', routes: >[ - TypedGoRoute(path: 'sub-route') + TypedGoRoute(path: 'sub-route'), ], ) class HomeRoute extends GoRouteData with _$HomeRoute { @@ -43,19 +41,20 @@ class SubRoute extends GoRouteData with _$SubRoute { Future onExit(BuildContext context, GoRouterState state) async { final bool? confirmed = await showDialog( context: context, - builder: (_) => AlertDialog( - content: const Text('Are you sure to leave this page?'), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(false), - child: const Text('Cancel'), + builder: + (_) => AlertDialog( + content: const Text('Are you sure to leave this page?'), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(false), + child: const Text('Cancel'), + ), + ElevatedButton( + onPressed: () => Navigator.of(context).pop(true), + child: const Text('Confirm'), + ), + ], ), - ElevatedButton( - onPressed: () => Navigator.of(context).pop(true), - child: const Text('Confirm'), - ), - ], - ), ); return confirmed ?? false; } @@ -69,13 +68,14 @@ class HomeScreen extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: const Text(_appTitle)), - body: Center( - child: ElevatedButton( - onPressed: () => const SubRoute().go(context), - child: const Text('Go to sub screen'), - ), - )); + appBar: AppBar(title: const Text(_appTitle)), + body: Center( + child: ElevatedButton( + onPressed: () => const SubRoute().go(context), + child: const Text('Go to sub screen'), + ), + ), + ); } class SubScreen extends StatelessWidget { @@ -83,14 +83,14 @@ class SubScreen extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: const Text('$_appTitle Sub screen')), - body: Center( - child: ElevatedButton( - onPressed: () => Navigator.of(context).pop(), - child: const Text('Go back'), - ), - ), - ); + appBar: AppBar(title: const Text('$_appTitle Sub screen')), + body: Center( + child: ElevatedButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text('Go back'), + ), + ), + ); } const String _appTitle = 'GoRouter Example: builder'; 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 458ccc0371b..82a5341efce 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 @@ -8,28 +8,21 @@ part of 'on_exit_example.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $homeRoute, - ]; +List get $appRoutes => [$homeRoute]; RouteBase get $homeRoute => GoRouteData.$route( - path: '/', - factory: _$HomeRoute._fromState, - routes: [ - GoRouteData.$route( - path: 'sub-route', - factory: _$SubRoute._fromState, - ), - ], - ); + path: '/', + factory: _$HomeRoute._fromState, + routes: [ + GoRouteData.$route(path: 'sub-route', factory: _$SubRoute._fromState), + ], +); mixin _$HomeRoute on GoRouteData { static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); @override - String get location => GoRouteData.$location( - '/', - ); + String get location => GoRouteData.$location('/'); @override void go(BuildContext context) => context.go(location); @@ -49,9 +42,7 @@ mixin _$SubRoute on GoRouteData { static SubRoute _fromState(GoRouterState state) => const SubRoute(); @override - String get location => GoRouteData.$location( - '/sub-route', - ); + String get location => GoRouteData.$location('/sub-route'); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/example/lib/readme_excerpts.dart b/packages/go_router_builder/example/lib/readme_excerpts.dart index af4cc03843b..e4a457497cd 100644 --- a/packages/go_router_builder/example/lib/readme_excerpts.dart +++ b/packages/go_router_builder/example/lib/readme_excerpts.dart @@ -81,9 +81,7 @@ void otherDoc(BuildContext context) { @TypedGoRoute( path: '/', routes: >[ - TypedGoRoute( - path: 'family/:fid', - ), + TypedGoRoute(path: 'family/:fid'), ], ) // #docregion HomeRoute @@ -125,14 +123,13 @@ class HomeScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: const Text('home'), - ), + appBar: AppBar(title: const Text('home')), body: TextButton( onPressed: () async { // #docregion awaitPush - final bool? result = - await const FamilyRoute(fid: 'John').push(context); + final bool? result = await const FamilyRoute( + fid: 'John', + ).push(context); // #enddocregion awaitPush print('result is $result'); }, @@ -161,9 +158,7 @@ class FamilyScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: const Text('family'), - ), + appBar: AppBar(title: const Text('family')), body: TextButton( onPressed: () { context.pop(true); @@ -194,9 +189,7 @@ class ErrorScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: const Text('Error'), - ), + appBar: AppBar(title: const Text('Error')), body: Text(error.toString()), ); } @@ -208,11 +201,7 @@ class LoginScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Login'), - ), - ); + return Scaffold(appBar: AppBar(title: const Text('Login'))); } } @@ -235,11 +224,7 @@ class MyScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('MyScreen'), - ), - ); + return Scaffold(appBar: AppBar(title: const Text('MyScreen'))); } } @@ -262,11 +247,7 @@ class PersonScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('PersonScreen'), - ), - ); + return Scaffold(appBar: AppBar(title: const Text('PersonScreen'))); } } @@ -296,11 +277,7 @@ class HotdogScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Hotdog'), - ), - ); + return Scaffold(appBar: AppBar(title: const Text('Hotdog'))); } } @@ -325,11 +302,7 @@ class BooksScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('BooksScreen'), - ), - ); + return Scaffold(appBar: AppBar(title: const Text('BooksScreen'))); } } @@ -340,10 +313,7 @@ class MyMaterialRouteWithKey extends GoRouteData with _$MyMaterialRouteWithKey { static const LocalKey _key = ValueKey('my-route-with-key'); @override MaterialPage buildPage(BuildContext context, GoRouterState state) { - return const MaterialPage( - key: _key, - child: MyPage(), - ); + return const MaterialPage(key: _key, child: MyPage()); } } // #enddocregion MyMaterialRouteWithKey @@ -353,11 +323,7 @@ class MyPage extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('MyPage'), - ), - ); + return Scaffold(appBar: AppBar(title: const Text('MyPage'))); } } @@ -368,9 +334,7 @@ class MyShellRoutePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: const Text('MyShellRoutePage'), - ), + appBar: AppBar(title: const Text('MyShellRoutePage')), body: child, ); } @@ -386,12 +350,17 @@ class FancyRoute extends GoRouteData with _$FancyRoute { GoRouterState state, ) { return CustomTransitionPage( - key: state.pageKey, - child: const MyPage(), - transitionsBuilder: (BuildContext context, Animation animation, - Animation secondaryAnimation, Widget child) { - return RotationTransition(turns: animation, child: child); - }); + key: state.pageKey, + child: const MyPage(), + transitionsBuilder: ( + BuildContext context, + Animation animation, + Animation secondaryAnimation, + Widget child, + ) { + return RotationTransition(turns: animation, child: child); + }, + ); } } // #enddocregion FancyRoute @@ -425,4 +394,5 @@ class MyGoRouteData extends GoRouteData with _$MyGoRouteData { @override Widget build(BuildContext context, GoRouterState state) => const MyPage(); } + // #enddocregion MyShellRouteData 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 6a6ff0c69b6..1a643f748f8 100644 --- a/packages/go_router_builder/example/lib/readme_excerpts.g.dart +++ b/packages/go_router_builder/example/lib/readme_excerpts.g.dart @@ -9,35 +9,30 @@ part of 'readme_excerpts.dart'; // ************************************************************************** List get $appRoutes => [ - $homeRoute, - $loginRoute, - $myRoute, - $personRouteWithExtra, - $hotdogRouteWithEverything, - $booksRoute, - $myMaterialRouteWithKey, - $fancyRoute, - $myShellRouteData, - ]; + $homeRoute, + $loginRoute, + $myRoute, + $personRouteWithExtra, + $hotdogRouteWithEverything, + $booksRoute, + $myMaterialRouteWithKey, + $fancyRoute, + $myShellRouteData, +]; RouteBase get $homeRoute => GoRouteData.$route( - path: '/', - factory: _$HomeRoute._fromState, - routes: [ - GoRouteData.$route( - path: 'family/:fid', - factory: _$FamilyRoute._fromState, - ), - ], - ); + path: '/', + factory: _$HomeRoute._fromState, + routes: [ + GoRouteData.$route(path: 'family/:fid', factory: _$FamilyRoute._fromState), + ], +); mixin _$HomeRoute on GoRouteData { static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); @override - String get location => GoRouteData.$location( - '/', - ); + String get location => GoRouteData.$location('/'); @override void go(BuildContext context) => context.go(location); @@ -54,16 +49,14 @@ mixin _$HomeRoute on GoRouteData { } mixin _$FamilyRoute on GoRouteData { - static FamilyRoute _fromState(GoRouterState state) => FamilyRoute( - fid: state.pathParameters['fid'], - ); + 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(_self.fid ?? '')}', - ); + String get location => + GoRouteData.$location('/family/${Uri.encodeComponent(_self.fid ?? '')}'); @override void go(BuildContext context) => context.go(location); @@ -79,25 +72,20 @@ mixin _$FamilyRoute on GoRouteData { void replace(BuildContext context) => context.replace(location); } -RouteBase get $loginRoute => GoRouteData.$route( - path: '/login', - factory: _$LoginRoute._fromState, - ); +RouteBase get $loginRoute => + GoRouteData.$route(path: '/login', factory: _$LoginRoute._fromState); mixin _$LoginRoute on GoRouteData { - static LoginRoute _fromState(GoRouterState state) => LoginRoute( - from: state.uri.queryParameters['from'], - ); + 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 (_self.from != null) 'from': _self.from, - }, - ); + '/login', + queryParams: {if (_self.from != null) 'from': _self.from}, + ); @override void go(BuildContext context) => context.go(location); @@ -113,27 +101,25 @@ mixin _$LoginRoute on GoRouteData { void replace(BuildContext context) => context.replace(location); } -RouteBase get $myRoute => GoRouteData.$route( - path: '/my-route', - factory: _$MyRoute._fromState, - ); +RouteBase get $myRoute => + GoRouteData.$route(path: '/my-route', factory: _$MyRoute._fromState); mixin _$MyRoute on GoRouteData { static MyRoute _fromState(GoRouterState state) => MyRoute( - queryParameter: - state.uri.queryParameters['query-parameter'] ?? 'defaultValue', - ); + queryParameter: + state.uri.queryParameters['query-parameter'] ?? 'defaultValue', + ); MyRoute get _self => this as MyRoute; @override String get location => GoRouteData.$location( - '/my-route', - queryParams: { - if (_self.queryParameter != 'defaultValue') - 'query-parameter': _self.queryParameter, - }, - ); + '/my-route', + queryParams: { + if (_self.queryParameter != 'defaultValue') + 'query-parameter': _self.queryParameter, + }, + ); @override void go(BuildContext context) => context.go(location); @@ -150,22 +136,18 @@ mixin _$MyRoute on GoRouteData { } RouteBase get $personRouteWithExtra => GoRouteData.$route( - path: '/person', - factory: _$PersonRouteWithExtra._fromState, - ); + path: '/person', + factory: _$PersonRouteWithExtra._fromState, +); mixin _$PersonRouteWithExtra on GoRouteData { static PersonRouteWithExtra _fromState(GoRouterState state) => - PersonRouteWithExtra( - state.extra as Person?, - ); + PersonRouteWithExtra(state.extra as Person?); PersonRouteWithExtra get _self => this as PersonRouteWithExtra; @override - String get location => GoRouteData.$location( - '/person', - ); + String get location => GoRouteData.$location('/person'); @override void go(BuildContext context) => context.go(location, extra: _self.$extra); @@ -184,9 +166,9 @@ mixin _$PersonRouteWithExtra on GoRouteData { } RouteBase get $hotdogRouteWithEverything => GoRouteData.$route( - path: '/:ketchup', - factory: _$HotdogRouteWithEverything._fromState, - ); + path: '/:ketchup', + factory: _$HotdogRouteWithEverything._fromState, +); mixin _$HotdogRouteWithEverything on GoRouteData { static HotdogRouteWithEverything _fromState(GoRouterState state) => @@ -200,11 +182,9 @@ mixin _$HotdogRouteWithEverything on GoRouteData { @override String get location => GoRouteData.$location( - '/${Uri.encodeComponent(_self.ketchup.toString())}', - queryParams: { - if (_self.mustard != null) 'mustard': _self.mustard, - }, - ); + '/${Uri.encodeComponent(_self.ketchup.toString())}', + queryParams: {if (_self.mustard != null) 'mustard': _self.mustard}, + ); @override void go(BuildContext context) => context.go(location, extra: _self.$extra); @@ -233,28 +213,29 @@ bool _$boolConverter(String value) { } } -RouteBase get $booksRoute => GoRouteData.$route( - path: '/books', - factory: _$BooksRoute._fromState, - ); +RouteBase get $booksRoute => + GoRouteData.$route(path: '/books', factory: _$BooksRoute._fromState); mixin _$BooksRoute on GoRouteData { static BooksRoute _fromState(GoRouterState state) => BooksRoute( - kind: _$convertMapValue('kind', state.uri.queryParameters, - _$BookKindEnumMap._$fromName) ?? - BookKind.popular, - ); + kind: + _$convertMapValue( + 'kind', + state.uri.queryParameters, + _$BookKindEnumMap._$fromName, + ) ?? + BookKind.popular, + ); BooksRoute get _self => this as BooksRoute; @override String get location => GoRouteData.$location( - '/books', - queryParams: { - if (_self.kind != BookKind.popular) - 'kind': _$BookKindEnumMap[_self.kind], - }, - ); + '/books', + queryParams: { + if (_self.kind != BookKind.popular) 'kind': _$BookKindEnumMap[_self.kind], + }, + ); @override void go(BuildContext context) => context.go(location); @@ -291,18 +272,16 @@ extension on Map { } RouteBase get $myMaterialRouteWithKey => GoRouteData.$route( - path: '/my-material-route-with-key', - factory: _$MyMaterialRouteWithKey._fromState, - ); + path: '/my-material-route-with-key', + factory: _$MyMaterialRouteWithKey._fromState, +); mixin _$MyMaterialRouteWithKey on GoRouteData { static MyMaterialRouteWithKey _fromState(GoRouterState state) => const MyMaterialRouteWithKey(); @override - String get location => GoRouteData.$location( - '/my-material-route-with-key', - ); + String get location => GoRouteData.$location('/my-material-route-with-key'); @override void go(BuildContext context) => context.go(location); @@ -318,18 +297,14 @@ mixin _$MyMaterialRouteWithKey on GoRouteData { void replace(BuildContext context) => context.replace(location); } -RouteBase get $fancyRoute => GoRouteData.$route( - path: '/fancy', - factory: _$FancyRoute._fromState, - ); +RouteBase get $fancyRoute => + GoRouteData.$route(path: '/fancy', factory: _$FancyRoute._fromState); mixin _$FancyRoute on GoRouteData { static FancyRoute _fromState(GoRouterState state) => const FancyRoute(); @override - String get location => GoRouteData.$location( - '/fancy', - ); + String get location => GoRouteData.$location('/fancy'); @override void go(BuildContext context) => context.go(location); @@ -346,16 +321,16 @@ mixin _$FancyRoute on GoRouteData { } RouteBase get $myShellRouteData => ShellRouteData.$route( - navigatorKey: MyShellRouteData.$navigatorKey, - factory: $MyShellRouteDataExtension._fromState, - routes: [ - GoRouteData.$route( - path: 'my-go-route', - parentNavigatorKey: MyGoRouteData.$parentNavigatorKey, - factory: _$MyGoRouteData._fromState, - ), - ], - ); + navigatorKey: MyShellRouteData.$navigatorKey, + factory: $MyShellRouteDataExtension._fromState, + routes: [ + GoRouteData.$route( + path: 'my-go-route', + parentNavigatorKey: MyGoRouteData.$parentNavigatorKey, + factory: _$MyGoRouteData._fromState, + ), + ], +); extension $MyShellRouteDataExtension on MyShellRouteData { static MyShellRouteData _fromState(GoRouterState state) => @@ -366,9 +341,7 @@ mixin _$MyGoRouteData on GoRouteData { static MyGoRouteData _fromState(GoRouterState state) => const MyGoRouteData(); @override - String get location => GoRouteData.$location( - 'my-go-route', - ); + String get location => GoRouteData.$location('my-go-route'); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/example/lib/shared/data.dart b/packages/go_router_builder/example/lib/shared/data.dart index 20f7c92d444..06cba5633d1 100644 --- a/packages/go_router_builder/example/lib/shared/data.dart +++ b/packages/go_router_builder/example/lib/shared/data.dart @@ -8,11 +8,7 @@ import 'dart:math'; import 'package:flutter/foundation.dart'; -enum PersonDetails { - hobbies, - favoriteFood, - favoriteSport, -} +enum PersonDetails { hobbies, favoriteFood, favoriteSport } enum SportDetails { volleyball( @@ -38,8 +34,7 @@ enum SportDetails { playerPerTeam: 6, accessory: 'Hockey sticks', hasNet: true, - ), - ; + ); const SportDetails({ required this.accessory, @@ -55,11 +50,7 @@ enum SportDetails { } /// An enum used only in iterables. -enum CookingRecipe { - burger, - pizza, - tacos, -} +enum CookingRecipe { burger, pizza, tacos } /// sample Person class class Person { @@ -85,9 +76,9 @@ class Family { final List people; Person person(int pid) => people.singleWhere( - (Person p) => p.id == pid, - orElse: () => throw Exception('unknown person $pid for family $id'), - ); + (Person p) => p.id == pid, + orElse: () => throw Exception('unknown person $pid for family $id'), + ); } final List familyData = [ @@ -95,11 +86,16 @@ final List familyData = [ id: 'f1', name: 'Sells', people: [ - Person(id: 1, name: 'Chris', age: 52, details: { - PersonDetails.hobbies: 'coding', - PersonDetails.favoriteFood: 'all of the above', - PersonDetails.favoriteSport: 'football?' - }), + Person( + id: 1, + name: 'Chris', + age: 52, + details: { + PersonDetails.hobbies: 'coding', + PersonDetails.favoriteFood: 'all of the above', + PersonDetails.favoriteSport: 'football?', + }, + ), Person(id: 2, name: 'John', age: 27), Person(id: 3, name: 'Tom', age: 26), ], @@ -141,9 +137,9 @@ Family familyById(String fid) => familyData.family(fid); extension on List { Family family(String fid) => singleWhere( - (Family f) => f.id == fid, - orElse: () => throw Exception('unknown family $fid'), - ); + (Family f) => f.id == fid, + orElse: () => throw Exception('unknown family $fid'), + ); } class LoginInfo extends ChangeNotifier { 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 fbbc078cf81..25b0ec53f02 100644 --- a/packages/go_router_builder/example/lib/shell_route_example.dart +++ b/packages/go_router_builder/example/lib/shell_route_example.dart @@ -15,9 +15,8 @@ class App extends StatelessWidget { App({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router); final GoRouter _router = GoRouter( routes: $appRoutes, @@ -29,9 +28,8 @@ class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); @override - Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: const Text('foo')), - ); + Widget build(BuildContext context) => + Scaffold(appBar: AppBar(title: const Text('foo'))); } @TypedShellRoute( @@ -44,11 +42,7 @@ class MyShellRouteData extends ShellRouteData { const MyShellRouteData(); @override - Widget builder( - BuildContext context, - GoRouterState state, - Widget navigator, - ) { + Widget builder(BuildContext context, GoRouterState state, Widget navigator) { return MyShellRouteScreen(child: navigator); } } @@ -92,14 +86,8 @@ class MyShellRouteScreen extends StatelessWidget { bottomNavigationBar: BottomNavigationBar( currentIndex: currentIndex, items: const [ - BottomNavigationBarItem( - icon: Icon(Icons.home), - label: 'Foo', - ), - BottomNavigationBarItem( - icon: Icon(Icons.business), - label: 'Bar', - ), + BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Foo'), + BottomNavigationBarItem(icon: Icon(Icons.business), label: 'Bar'), ], onTap: (int index) { switch (index) { 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 0b2e61ebee3..06d8e7e444f 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 @@ -8,24 +8,15 @@ part of 'shell_route_example.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $myShellRouteData, - $loginRoute, - ]; +List get $appRoutes => [$myShellRouteData, $loginRoute]; RouteBase get $myShellRouteData => ShellRouteData.$route( - factory: $MyShellRouteDataExtension._fromState, - routes: [ - GoRouteData.$route( - path: '/foo', - factory: _$FooRouteData._fromState, - ), - GoRouteData.$route( - path: '/bar', - factory: _$BarRouteData._fromState, - ), - ], - ); + factory: $MyShellRouteDataExtension._fromState, + routes: [ + GoRouteData.$route(path: '/foo', factory: _$FooRouteData._fromState), + GoRouteData.$route(path: '/bar', factory: _$BarRouteData._fromState), + ], +); extension $MyShellRouteDataExtension on MyShellRouteData { static MyShellRouteData _fromState(GoRouterState state) => @@ -36,9 +27,7 @@ mixin _$FooRouteData on GoRouteData { static FooRouteData _fromState(GoRouterState state) => const FooRouteData(); @override - String get location => GoRouteData.$location( - '/foo', - ); + String get location => GoRouteData.$location('/foo'); @override void go(BuildContext context) => context.go(location); @@ -58,9 +47,7 @@ mixin _$BarRouteData on GoRouteData { static BarRouteData _fromState(GoRouterState state) => const BarRouteData(); @override - String get location => GoRouteData.$location( - '/bar', - ); + String get location => GoRouteData.$location('/bar'); @override void go(BuildContext context) => context.go(location); @@ -76,18 +63,14 @@ mixin _$BarRouteData on GoRouteData { void replace(BuildContext context) => context.replace(location); } -RouteBase get $loginRoute => GoRouteData.$route( - path: '/login', - factory: _$LoginRoute._fromState, - ); +RouteBase get $loginRoute => + GoRouteData.$route(path: '/login', factory: _$LoginRoute._fromState); mixin _$LoginRoute on GoRouteData { static LoginRoute _fromState(GoRouterState state) => const LoginRoute(); @override - String get location => GoRouteData.$location( - '/login', - ); + String get location => GoRouteData.$location('/login'); @override void go(BuildContext context) => context.go(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 415a8f0b31b..afdf4a03c38 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 @@ -18,9 +18,8 @@ class App extends StatelessWidget { App({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router); final GoRouter _router = GoRouter( routes: $appRoutes, 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 759588b2d28..b3cb84bd5b8 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 @@ -8,31 +8,26 @@ part of 'shell_route_with_keys_example.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $myShellRouteData, - ]; +List get $appRoutes => [$myShellRouteData]; RouteBase get $myShellRouteData => ShellRouteData.$route( - navigatorKey: MyShellRouteData.$navigatorKey, - factory: $MyShellRouteDataExtension._fromState, + navigatorKey: MyShellRouteData.$navigatorKey, + factory: $MyShellRouteDataExtension._fromState, + routes: [ + GoRouteData.$route(path: '/home', factory: _$HomeRouteData._fromState), + GoRouteData.$route( + path: '/users', + factory: _$UsersRouteData._fromState, routes: [ GoRouteData.$route( - path: '/home', - factory: _$HomeRouteData._fromState, - ), - GoRouteData.$route( - path: '/users', - factory: _$UsersRouteData._fromState, - routes: [ - GoRouteData.$route( - path: ':id', - parentNavigatorKey: UserRouteData.$parentNavigatorKey, - factory: _$UserRouteData._fromState, - ), - ], + path: ':id', + parentNavigatorKey: UserRouteData.$parentNavigatorKey, + factory: _$UserRouteData._fromState, ), ], - ); + ), + ], +); extension $MyShellRouteDataExtension on MyShellRouteData { static MyShellRouteData _fromState(GoRouterState state) => @@ -43,9 +38,7 @@ mixin _$HomeRouteData on GoRouteData { static HomeRouteData _fromState(GoRouterState state) => const HomeRouteData(); @override - String get location => GoRouteData.$location( - '/home', - ); + String get location => GoRouteData.$location('/home'); @override void go(BuildContext context) => context.go(location); @@ -66,9 +59,7 @@ mixin _$UsersRouteData on GoRouteData { const UsersRouteData(); @override - String get location => GoRouteData.$location( - '/users', - ); + String get location => GoRouteData.$location('/users'); @override void go(BuildContext context) => context.go(location); @@ -85,16 +76,15 @@ mixin _$UsersRouteData on GoRouteData { } mixin _$UserRouteData on GoRouteData { - static UserRouteData _fromState(GoRouterState state) => UserRouteData( - id: int.parse(state.pathParameters['id']!)!, - ); + 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(_self.id.toString())}', - ); + '/users/${Uri.encodeComponent(_self.id.toString())}', + ); @override void go(BuildContext context) => context.go(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 326068ba8bc..5c8bf0d00ca 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 @@ -15,9 +15,8 @@ class App extends StatelessWidget { App({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router); final GoRouter _router = GoRouter( routes: $appRoutes, @@ -40,7 +39,7 @@ class MyShellRouteData extends ShellRouteData { const MyShellRouteData(); static final List $observers = [ - MyNavigatorObserver() + MyNavigatorObserver(), ]; @override 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 e510a5f3a80..caa853af7a1 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 @@ -8,30 +8,22 @@ part of 'shell_route_with_observers_example.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $myShellRouteData, - ]; +List get $appRoutes => [$myShellRouteData]; RouteBase get $myShellRouteData => ShellRouteData.$route( - observers: MyShellRouteData.$observers, - factory: $MyShellRouteDataExtension._fromState, + observers: MyShellRouteData.$observers, + factory: $MyShellRouteDataExtension._fromState, + routes: [ + GoRouteData.$route(path: '/home', factory: _$HomeRouteData._fromState), + GoRouteData.$route( + path: '/users', + factory: _$UsersRouteData._fromState, routes: [ - GoRouteData.$route( - path: '/home', - factory: _$HomeRouteData._fromState, - ), - GoRouteData.$route( - path: '/users', - factory: _$UsersRouteData._fromState, - routes: [ - GoRouteData.$route( - path: ':id', - factory: _$UserRouteData._fromState, - ), - ], - ), + GoRouteData.$route(path: ':id', factory: _$UserRouteData._fromState), ], - ); + ), + ], +); extension $MyShellRouteDataExtension on MyShellRouteData { static MyShellRouteData _fromState(GoRouterState state) => @@ -42,9 +34,7 @@ mixin _$HomeRouteData on GoRouteData { static HomeRouteData _fromState(GoRouterState state) => const HomeRouteData(); @override - String get location => GoRouteData.$location( - '/home', - ); + String get location => GoRouteData.$location('/home'); @override void go(BuildContext context) => context.go(location); @@ -65,9 +55,7 @@ mixin _$UsersRouteData on GoRouteData { const UsersRouteData(); @override - String get location => GoRouteData.$location( - '/users', - ); + String get location => GoRouteData.$location('/users'); @override void go(BuildContext context) => context.go(location); @@ -84,16 +72,15 @@ mixin _$UsersRouteData on GoRouteData { } mixin _$UserRouteData on GoRouteData { - static UserRouteData _fromState(GoRouterState state) => UserRouteData( - id: int.parse(state.pathParameters['id']!)!, - ); + 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(_self.id.toString())}', - ); + '/users/${Uri.encodeComponent(_self.id.toString())}', + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/example/lib/simple_example.dart b/packages/go_router_builder/example/lib/simple_example.dart index a2e946c49e0..b3344726092 100644 --- a/packages/go_router_builder/example/lib/simple_example.dart +++ b/packages/go_router_builder/example/lib/simple_example.dart @@ -17,10 +17,8 @@ class App extends StatelessWidget { App({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - title: _appTitle, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router, title: _appTitle); final GoRouter _router = GoRouter(routes: $appRoutes); } @@ -29,7 +27,7 @@ class App extends StatelessWidget { path: '/', name: 'Home', routes: >[ - TypedGoRoute(path: 'family/:familyId') + TypedGoRoute(path: 'family/:familyId'), ], ) class HomeRoute extends GoRouteData with _$HomeRoute { @@ -55,17 +53,17 @@ class HomeScreen extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: const Text(_appTitle)), - body: ListView( - children: [ - for (final Family family in familyData) - ListTile( - title: Text(family.name), - onTap: () => FamilyRoute(family.id).go(context), - ) - ], - ), - ); + appBar: AppBar(title: const Text(_appTitle)), + body: ListView( + children: [ + for (final Family family in familyData) + ListTile( + title: Text(family.name), + onTap: () => FamilyRoute(family.id).go(context), + ), + ], + ), + ); } class FamilyScreen extends StatelessWidget { @@ -74,16 +72,13 @@ class FamilyScreen extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: Text(family.name)), - body: ListView( - children: [ - for (final Person p in family.people) - ListTile( - title: Text(p.name), - ), - ], - ), - ); + appBar: AppBar(title: Text(family.name)), + body: ListView( + children: [ + for (final Person p in family.people) ListTile(title: Text(p.name)), + ], + ), + ); } const String _appTitle = 'GoRouter Example: builder'; 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 4ecd74e3cbf..07c934bdcc6 100644 --- a/packages/go_router_builder/example/lib/simple_example.g.dart +++ b/packages/go_router_builder/example/lib/simple_example.g.dart @@ -8,29 +8,25 @@ part of 'simple_example.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $homeRoute, - ]; +List get $appRoutes => [$homeRoute]; RouteBase get $homeRoute => GoRouteData.$route( - path: '/', - name: 'Home', - factory: _$HomeRoute._fromState, - routes: [ - GoRouteData.$route( - path: 'family/:familyId', - factory: _$FamilyRoute._fromState, - ), - ], - ); + path: '/', + name: 'Home', + factory: _$HomeRoute._fromState, + routes: [ + GoRouteData.$route( + path: 'family/:familyId', + factory: _$FamilyRoute._fromState, + ), + ], +); mixin _$HomeRoute on GoRouteData { static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); @override - String get location => GoRouteData.$location( - '/', - ); + String get location => GoRouteData.$location('/'); @override void go(BuildContext context) => context.go(location); @@ -47,16 +43,14 @@ mixin _$HomeRoute on GoRouteData { } mixin _$FamilyRoute on GoRouteData { - static FamilyRoute _fromState(GoRouterState state) => FamilyRoute( - state.pathParameters['familyId']!, - ); + static FamilyRoute _fromState(GoRouterState state) => + FamilyRoute(state.pathParameters['familyId']!); FamilyRoute get _self => this as FamilyRoute; @override - String get location => GoRouteData.$location( - '/family/${Uri.encodeComponent(_self.familyId)}', - ); + String get location => + GoRouteData.$location('/family/${Uri.encodeComponent(_self.familyId)}'); @override void go(BuildContext context) => context.go(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 6889403bc3a..99da40fe16f 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 @@ -19,9 +19,8 @@ class App extends StatelessWidget { App({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router); final GoRouter _router = GoRouter( routes: $appRoutes, @@ -33,9 +32,8 @@ class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); @override - Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: const Text('foo')), - ); + Widget build(BuildContext context) => + Scaffold(appBar: AppBar(title: const Text('foo'))); } @TypedStatefulShellRoute( @@ -66,8 +64,11 @@ class MyShellRouteData extends StatefulShellRouteData { static const String $restorationScopeId = 'restorationScopeId'; - static Widget $navigatorContainerBuilder(BuildContext context, - StatefulNavigationShell navigationShell, List children) { + static Widget $navigatorContainerBuilder( + BuildContext context, + StatefulNavigationShell navigationShell, + List children, + ) { return ScaffoldWithNavBar( navigationShell: navigationShell, children: children, @@ -164,8 +165,11 @@ class ScaffoldWithNavBar extends StatelessWidget { /// when switching branches. class AnimatedBranchContainer extends StatelessWidget { /// Creates a AnimatedBranchContainer - const AnimatedBranchContainer( - {super.key, required this.currentIndex, required this.children}); + const AnimatedBranchContainer({ + super.key, + required this.currentIndex, + required this.children, + }); /// The index (in [children]) of the branch Navigator to display. final int currentIndex; @@ -176,39 +180,31 @@ class AnimatedBranchContainer extends StatelessWidget { @override Widget build(BuildContext context) { return Stack( - children: children.mapIndexed( - (int index, Widget navigator) { - return AnimatedScale( - scale: index == currentIndex ? 1 : 1.5, - duration: const Duration(milliseconds: 400), - child: AnimatedOpacity( - opacity: index == currentIndex ? 1 : 0, - duration: const Duration(milliseconds: 400), - child: _branchNavigatorWrapper(index, navigator), - ), - ); - }, - ).toList()); + children: + children.mapIndexed((int index, Widget navigator) { + return AnimatedScale( + scale: index == currentIndex ? 1 : 1.5, + duration: const Duration(milliseconds: 400), + child: AnimatedOpacity( + opacity: index == currentIndex ? 1 : 0, + duration: const Duration(milliseconds: 400), + child: _branchNavigatorWrapper(index, navigator), + ), + ); + }).toList(), + ); } Widget _branchNavigatorWrapper(int index, Widget navigator) => IgnorePointer( - ignoring: index != currentIndex, - child: TickerMode( - enabled: index == currentIndex, - child: navigator, - ), - ); + ignoring: index != currentIndex, + child: TickerMode(enabled: index == currentIndex, child: navigator), + ); } /// The details screen for either the A or B screen. class DetailsScreen extends StatefulWidget { /// Constructs a [DetailsScreen]. - const DetailsScreen({ - required this.label, - this.param, - this.extra, - super.key, - }); + const DetailsScreen({required this.label, this.param, this.extra, super.key}); /// The label to display in the center of the screen. final String label; @@ -229,9 +225,7 @@ class DetailsScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text('Details Screen - ${widget.label}'), - ), + appBar: AppBar(title: Text('Details Screen - ${widget.label}')), body: _build(context), ); } @@ -241,8 +235,10 @@ class DetailsScreenState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - Text('Details for ${widget.label} - Counter: $_counter', - style: Theme.of(context).textTheme.titleLarge), + Text( + 'Details for ${widget.label} - Counter: $_counter', + style: Theme.of(context).textTheme.titleLarge, + ), const Padding(padding: EdgeInsets.all(4)), TextButton( onPressed: () { @@ -254,12 +250,16 @@ class DetailsScreenState extends State { ), const Padding(padding: EdgeInsets.all(8)), if (widget.param != null) - Text('Parameter: ${widget.param!}', - style: Theme.of(context).textTheme.titleMedium), + Text( + 'Parameter: ${widget.param!}', + style: Theme.of(context).textTheme.titleMedium, + ), const Padding(padding: EdgeInsets.all(8)), if (widget.extra != null) - Text('Extra: ${widget.extra!}', - style: Theme.of(context).textTheme.titleMedium), + Text( + 'Extra: ${widget.extra!}', + style: Theme.of(context).textTheme.titleMedium, + ), ], ), ); 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 d0eaa8ddf6a..5dc4e42fc06 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 @@ -8,35 +8,33 @@ part of 'stateful_shell_route_example.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $myShellRouteData, - ]; +List get $appRoutes => [$myShellRouteData]; RouteBase get $myShellRouteData => StatefulShellRouteData.$route( - restorationScopeId: MyShellRouteData.$restorationScopeId, - navigatorContainerBuilder: MyShellRouteData.$navigatorContainerBuilder, - factory: $MyShellRouteDataExtension._fromState, - branches: [ - StatefulShellBranchData.$branch( - routes: [ - GoRouteData.$route( - path: '/detailsA', - factory: _$DetailsARouteData._fromState, - ), - ], + restorationScopeId: MyShellRouteData.$restorationScopeId, + navigatorContainerBuilder: MyShellRouteData.$navigatorContainerBuilder, + factory: $MyShellRouteDataExtension._fromState, + branches: [ + StatefulShellBranchData.$branch( + routes: [ + GoRouteData.$route( + path: '/detailsA', + factory: _$DetailsARouteData._fromState, ), - StatefulShellBranchData.$branch( - navigatorKey: BranchBData.$navigatorKey, - restorationScopeId: BranchBData.$restorationScopeId, - routes: [ - GoRouteData.$route( - path: '/detailsB', - factory: _$DetailsBRouteData._fromState, - ), - ], + ], + ), + StatefulShellBranchData.$branch( + navigatorKey: BranchBData.$navigatorKey, + restorationScopeId: BranchBData.$restorationScopeId, + routes: [ + GoRouteData.$route( + path: '/detailsB', + factory: _$DetailsBRouteData._fromState, ), ], - ); + ), + ], +); extension $MyShellRouteDataExtension on MyShellRouteData { static MyShellRouteData _fromState(GoRouterState state) => @@ -48,9 +46,7 @@ mixin _$DetailsARouteData on GoRouteData { const DetailsARouteData(); @override - String get location => GoRouteData.$location( - '/detailsA', - ); + String get location => GoRouteData.$location('/detailsA'); @override void go(BuildContext context) => context.go(location); @@ -71,9 +67,7 @@ mixin _$DetailsBRouteData on GoRouteData { const DetailsBRouteData(); @override - String get location => GoRouteData.$location( - '/detailsB', - ); + String get location => GoRouteData.$location('/detailsB'); @override void go(BuildContext context) => context.go(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 0e05a36e9ad..c9d2a8c9bbe 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 @@ -15,9 +15,8 @@ class App extends StatelessWidget { App({super.key}); @override - Widget build(BuildContext context) => MaterialApp.router( - routerConfig: _router, - ); + Widget build(BuildContext context) => + MaterialApp.router(routerConfig: _router); final GoRouter _router = GoRouter( routes: $appRoutes, @@ -29,32 +28,25 @@ class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); @override - Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: const Text('foo')), - ); + Widget build(BuildContext context) => + Scaffold(appBar: AppBar(title: const Text('foo'))); } @TypedStatefulShellRoute( branches: >[ TypedStatefulShellBranch( routes: >[ - TypedGoRoute( - path: '/home', - ), + TypedGoRoute(path: '/home'), ], ), TypedStatefulShellBranch( routes: >[ - TypedGoRoute( - path: '/notifications/:section', - ), + TypedGoRoute(path: '/notifications/:section'), ], ), TypedStatefulShellBranch( routes: >[ - TypedGoRoute( - path: '/orders', - ), + TypedGoRoute(path: '/orders'), ], ), ], @@ -68,9 +60,7 @@ class MainShellRouteData extends StatefulShellRouteData { GoRouterState state, StatefulNavigationShell navigationShell, ) { - return MainPageView( - navigationShell: navigationShell, - ); + return MainPageView(navigationShell: navigationShell); } } @@ -97,24 +87,16 @@ class HomeRouteData extends GoRouteData with _$HomeRouteData { } } -enum NotificationsPageSection { - latest, - old, - archive, -} +enum NotificationsPageSection { latest, old, archive } class NotificationsRouteData extends GoRouteData with _$NotificationsRouteData { - const NotificationsRouteData({ - required this.section, - }); + const NotificationsRouteData({required this.section}); final NotificationsPageSection section; @override Widget build(BuildContext context, GoRouterState state) { - return NotificationsPageView( - section: section, - ); + return NotificationsPageView(section: section); } } @@ -128,10 +110,7 @@ class OrdersRouteData extends GoRouteData with _$OrdersRouteData { } class MainPageView extends StatelessWidget { - const MainPageView({ - required this.navigationShell, - super.key, - }); + const MainPageView({required this.navigationShell, super.key}); final StatefulNavigationShell navigationShell; @@ -142,18 +121,12 @@ class MainPageView extends StatelessWidget { body: navigationShell, bottomNavigationBar: BottomNavigationBar( items: const [ - BottomNavigationBarItem( - icon: Icon(Icons.home), - label: 'Home', - ), + BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'), BottomNavigationBarItem( icon: Icon(Icons.favorite), label: 'Notifications', ), - BottomNavigationBarItem( - icon: Icon(Icons.list), - label: 'Orders', - ), + BottomNavigationBarItem(icon: Icon(Icons.list), label: 'Orders'), ], currentIndex: navigationShell.currentIndex, onTap: (int index) => _onTap(context, index), @@ -170,26 +143,18 @@ class MainPageView extends StatelessWidget { } class HomePageView extends StatelessWidget { - const HomePageView({ - required this.label, - super.key, - }); + const HomePageView({required this.label, super.key}); final String label; @override Widget build(BuildContext context) { - return Center( - child: Text(label), - ); + return Center(child: Text(label)); } } class NotificationsPageView extends StatelessWidget { - const NotificationsPageView({ - super.key, - required this.section, - }); + const NotificationsPageView({super.key, required this.section}); final NotificationsPageSection section; @@ -203,37 +168,20 @@ class NotificationsPageView extends StatelessWidget { TabBar( tabs: [ Tab( - child: Text( - 'Latest', - style: TextStyle(color: Colors.black87), - ), - ), - Tab( - child: Text( - 'Old', - style: TextStyle(color: Colors.black87), - ), + child: Text('Latest', style: TextStyle(color: Colors.black87)), ), + Tab(child: Text('Old', style: TextStyle(color: Colors.black87))), Tab( - child: Text( - 'Archive', - style: TextStyle(color: Colors.black87), - ), + child: Text('Archive', style: TextStyle(color: Colors.black87)), ), ], ), Expanded( child: TabBarView( children: [ - NotificationsSubPageView( - label: 'Latest notifications', - ), - NotificationsSubPageView( - label: 'Old notifications', - ), - NotificationsSubPageView( - label: 'Archived notifications', - ), + NotificationsSubPageView(label: 'Latest notifications'), + NotificationsSubPageView(label: 'Old notifications'), + NotificationsSubPageView(label: 'Archived notifications'), ], ), ), @@ -244,33 +192,23 @@ class NotificationsPageView extends StatelessWidget { } class NotificationsSubPageView extends StatelessWidget { - const NotificationsSubPageView({ - required this.label, - super.key, - }); + const NotificationsSubPageView({required this.label, super.key}); final String label; @override Widget build(BuildContext context) { - return Center( - child: Text(label), - ); + return Center(child: Text(label)); } } class OrdersPageView extends StatelessWidget { - const OrdersPageView({ - required this.label, - super.key, - }); + const OrdersPageView({required this.label, super.key}); final String label; @override Widget build(BuildContext context) { - return Center( - child: Text(label), - ); + return Center(child: Text(label)); } } 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 c7e63a1fc7f..b72a192e5a6 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 @@ -8,40 +8,35 @@ part of 'stateful_shell_route_initial_location_example.dart'; // GoRouterGenerator // ************************************************************************** -List get $appRoutes => [ - $mainShellRouteData, - ]; +List get $appRoutes => [$mainShellRouteData]; RouteBase get $mainShellRouteData => StatefulShellRouteData.$route( - factory: $MainShellRouteDataExtension._fromState, - branches: [ - StatefulShellBranchData.$branch( - routes: [ - GoRouteData.$route( - path: '/home', - factory: _$HomeRouteData._fromState, - ), - ], - ), - StatefulShellBranchData.$branch( - initialLocation: NotificationsShellBranchData.$initialLocation, - routes: [ - GoRouteData.$route( - path: '/notifications/:section', - factory: _$NotificationsRouteData._fromState, - ), - ], + factory: $MainShellRouteDataExtension._fromState, + branches: [ + StatefulShellBranchData.$branch( + routes: [ + GoRouteData.$route(path: '/home', factory: _$HomeRouteData._fromState), + ], + ), + StatefulShellBranchData.$branch( + initialLocation: NotificationsShellBranchData.$initialLocation, + routes: [ + GoRouteData.$route( + path: '/notifications/:section', + factory: _$NotificationsRouteData._fromState, ), - StatefulShellBranchData.$branch( - routes: [ - GoRouteData.$route( - path: '/orders', - factory: _$OrdersRouteData._fromState, - ), - ], + ], + ), + StatefulShellBranchData.$branch( + routes: [ + GoRouteData.$route( + path: '/orders', + factory: _$OrdersRouteData._fromState, ), ], - ); + ), + ], +); extension $MainShellRouteDataExtension on MainShellRouteData { static MainShellRouteData _fromState(GoRouterState state) => @@ -52,9 +47,7 @@ mixin _$HomeRouteData on GoRouteData { static HomeRouteData _fromState(GoRouterState state) => const HomeRouteData(); @override - String get location => GoRouteData.$location( - '/home', - ); + String get location => GoRouteData.$location('/home'); @override void go(BuildContext context) => context.go(location); @@ -73,16 +66,18 @@ mixin _$HomeRouteData on GoRouteData { mixin _$NotificationsRouteData on GoRouteData { static NotificationsRouteData _fromState(GoRouterState state) => NotificationsRouteData( - section: _$NotificationsPageSectionEnumMap - ._$fromName(state.pathParameters['section']!)!, + section: + _$NotificationsPageSectionEnumMap._$fromName( + state.pathParameters['section']!, + )!, ); NotificationsRouteData get _self => this as NotificationsRouteData; @override String get location => GoRouteData.$location( - '/notifications/${Uri.encodeComponent(_$NotificationsPageSectionEnumMap[_self.section]!)}', - ); + '/notifications/${Uri.encodeComponent(_$NotificationsPageSectionEnumMap[_self.section]!)}', + ); @override void go(BuildContext context) => context.go(location); @@ -109,9 +104,7 @@ mixin _$OrdersRouteData on GoRouteData { const OrdersRouteData(); @override - String get location => GoRouteData.$location( - '/orders', - ); + String get location => GoRouteData.$location('/orders'); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/example/pubspec.yaml b/packages/go_router_builder/example/pubspec.yaml index 93e165668d0..5543b0695cf 100644 --- a/packages/go_router_builder/example/pubspec.yaml +++ b/packages/go_router_builder/example/pubspec.yaml @@ -3,7 +3,7 @@ description: go_router_builder examples publish_to: none environment: - sdk: ^3.6.0 + sdk: ^3.7.0 dependencies: collection: ^1.15.0 diff --git a/packages/go_router_builder/example/test/all_types_test.dart b/packages/go_router_builder/example/test/all_types_test.dart index 89774f7f623..6ea2c7ba517 100644 --- a/packages/go_router_builder/example/test/all_types_test.dart +++ b/packages/go_router_builder/example/test/all_types_test.dart @@ -12,8 +12,9 @@ void main() { testWidgets('Test typed route navigation', (WidgetTester tester) async { await tester.pumpWidget(AllTypesApp()); - final ScaffoldState scaffoldState = - tester.firstState(find.byType(Scaffold)); + final ScaffoldState scaffoldState = tester.firstState( + find.byType(Scaffold), + ); BigIntRoute( requiredBigIntField: BigInt.from(4), @@ -56,10 +57,7 @@ void main() { expect(find.text('Query param: -3.14'), findsOneWidget); expect(find.text('Query param with default value: 1.0'), findsOneWidget); - IntRoute( - requiredIntField: 65, - intField: -65, - ).go(scaffoldState.context); + IntRoute(requiredIntField: 65, intField: -65).go(scaffoldState.context); await tester.pumpAndSettle(); expect(find.text('IntRoute'), findsOneWidget); expect(find.text('Param: 65'), findsOneWidget); @@ -82,13 +80,18 @@ void main() { ).go(scaffoldState.context); await tester.pumpAndSettle(); expect(find.text('StringRoute'), findsOneWidget); - expect(find.text('Param: Tytire tu patulae recubans sub tegmine fagi.'), - findsOneWidget); expect( - find.text('Query param: Tytire tu patulae recubans sub tegmine fagi.'), - findsOneWidget); - expect(find.text('Query param with default value: defaultValue'), - findsOneWidget); + find.text('Param: Tytire tu patulae recubans sub tegmine fagi.'), + findsOneWidget, + ); + expect( + find.text('Query param: Tytire tu patulae recubans sub tegmine fagi.'), + findsOneWidget, + ); + expect( + find.text('Query param with default value: defaultValue'), + findsOneWidget, + ); EnumRoute( requiredEnumField: PersonDetails.favoriteFood, @@ -98,7 +101,9 @@ void main() { expect(find.text('EnumRoute'), findsOneWidget); expect(find.text('Param: PersonDetails.favoriteFood'), findsOneWidget); expect( - find.text('Query param: PersonDetails.favoriteSport'), findsOneWidget); + find.text('Query param: PersonDetails.favoriteSport'), + findsOneWidget, + ); expect( find.text('Query param with default value: PersonDetails.favoriteFood'), findsOneWidget, @@ -138,158 +143,190 @@ void main() { expect(find.text('IterableRoute'), findsOneWidget); expect(find.text('/iterable-route'), findsOneWidget); expect( - find.text( - '{enum-iterable-field: football, int-list-field: 3, enum-only-in-set-field: pizza}'), - findsOneWidget); + find.text( + '{enum-iterable-field: football, int-list-field: 3, enum-only-in-set-field: pizza}', + ), + findsOneWidget, + ); }); testWidgets( - 'It should navigate to the iterable route with its default values', - (WidgetTester tester) async { - await tester.pumpWidget(AllTypesApp()); + 'It should navigate to the iterable route with its default values', + (WidgetTester tester) async { + await tester.pumpWidget(AllTypesApp()); - final ScaffoldState scaffoldState = - tester.firstState(find.byType(Scaffold)); + final ScaffoldState scaffoldState = tester.firstState( + find.byType(Scaffold), + ); - const IterableRouteWithDefaultValues().go(scaffoldState.context); - await tester.pumpAndSettle(); - expect(find.text('IterableRouteWithDefaultValues'), findsOneWidget); - final IterablePage page = - tester.widget(find.byType(IterablePage)); - expect( - page, - isA().having( - (IterablePage page) => page.intIterableField, - 'intIterableField', - const [0], - ).having( - (IterablePage page) => page.intListField, - 'intListField', - const [0], - ).having( - (IterablePage page) => page.intSetField, - 'intSetField', - const {0, 1}, - ).having( - (IterablePage page) => page.doubleIterableField, - 'doubleIterableField', - const [0, 1, 2], - ).having( - (IterablePage page) => page.doubleListField, - 'doubleListField', - const [1, 2, 3], - ).having( - (IterablePage page) => page.doubleSetField, - 'doubleSetField', - const {}, - ).having( - (IterablePage page) => page.stringIterableField, - 'stringIterableField', - const ['defaultValue'], - ).having( - (IterablePage page) => page.stringListField, - 'stringListField', - const ['defaultValue0', 'defaultValue1'], - ).having( - (IterablePage page) => page.stringSetField, - 'stringSetField', - const {'defaultValue'}, - ).having( - (IterablePage page) => page.boolIterableField, - 'boolIterableField', - const [false], - ).having( - (IterablePage page) => page.boolListField, - 'boolListField', - const [true], - ).having( - (IterablePage page) => page.boolSetField, - 'boolSetField', - const {true, false}, - ).having( - (IterablePage page) => page.enumIterableField, - 'enumIterableField', - const [SportDetails.tennis, SportDetails.hockey], - ).having( - (IterablePage page) => page.enumListField, - 'enumListField', - const [SportDetails.football], - ).having( - (IterablePage page) => page.enumSetField, - 'enumSetField', - const {SportDetails.hockey}, - ), - ); - expect(find.text('/iterable-route-with-default-values'), findsOneWidget); - }); + const IterableRouteWithDefaultValues().go(scaffoldState.context); + await tester.pumpAndSettle(); + expect(find.text('IterableRouteWithDefaultValues'), findsOneWidget); + final IterablePage page = tester.widget( + find.byType(IterablePage), + ); + expect( + page, + isA() + .having( + (IterablePage page) => page.intIterableField, + 'intIterableField', + const [0], + ) + .having( + (IterablePage page) => page.intListField, + 'intListField', + const [0], + ) + .having( + (IterablePage page) => page.intSetField, + 'intSetField', + const {0, 1}, + ) + .having( + (IterablePage page) => page.doubleIterableField, + 'doubleIterableField', + const [0, 1, 2], + ) + .having( + (IterablePage page) => page.doubleListField, + 'doubleListField', + const [1, 2, 3], + ) + .having( + (IterablePage page) => page.doubleSetField, + 'doubleSetField', + const {}, + ) + .having( + (IterablePage page) => page.stringIterableField, + 'stringIterableField', + const ['defaultValue'], + ) + .having( + (IterablePage page) => page.stringListField, + 'stringListField', + const ['defaultValue0', 'defaultValue1'], + ) + .having( + (IterablePage page) => page.stringSetField, + 'stringSetField', + const {'defaultValue'}, + ) + .having( + (IterablePage page) => page.boolIterableField, + 'boolIterableField', + const [false], + ) + .having( + (IterablePage page) => page.boolListField, + 'boolListField', + const [true], + ) + .having( + (IterablePage page) => page.boolSetField, + 'boolSetField', + const {true, false}, + ) + .having( + (IterablePage page) => page.enumIterableField, + 'enumIterableField', + const [SportDetails.tennis, SportDetails.hockey], + ) + .having( + (IterablePage page) => page.enumListField, + 'enumListField', + const [SportDetails.football], + ) + .having( + (IterablePage page) => page.enumSetField, + 'enumSetField', + const {SportDetails.hockey}, + ), + ); + expect(find.text('/iterable-route-with-default-values'), findsOneWidget); + }, + ); testWidgets( - 'Test navigation with invalid query and path parameters using Uri.parse', - (WidgetTester tester) async { - await tester.pumpWidget(AllTypesApp()); + 'Test navigation with invalid query and path parameters using Uri.parse', + (WidgetTester tester) async { + await tester.pumpWidget(AllTypesApp()); - final ScaffoldState scaffoldState = - tester.firstState(find.byType(Scaffold)); + final ScaffoldState scaffoldState = tester.firstState( + find.byType(Scaffold), + ); - // Test invalid BigInt parameter - scaffoldState.context - .go(Uri.parse('/big-int-route/4?bigIntField=invalid').toString()); - await tester.pumpAndSettle(); - expect(find.text('BigIntRoute'), findsOneWidget); - expect(find.text('Param: 4'), findsOneWidget); - expect(find.text('Query param: null'), findsOneWidget); + // Test invalid BigInt parameter + scaffoldState.context.go( + Uri.parse('/big-int-route/4?bigIntField=invalid').toString(), + ); + await tester.pumpAndSettle(); + expect(find.text('BigIntRoute'), findsOneWidget); + expect(find.text('Param: 4'), findsOneWidget); + expect(find.text('Query param: null'), findsOneWidget); - // Test invalid DateTime parameter - scaffoldState.context.go(Uri.parse( - '/date-time-route/2021-01-01T00:00:00.000?dateTimeField=invalid-date') - .toString()); - await tester.pumpAndSettle(); - expect(find.text('DateTimeRoute'), findsOneWidget); - expect(find.text('Param: 2021-01-01 00:00:00.000'), findsOneWidget); - expect(find.text('Query param: null'), findsOneWidget); + // Test invalid DateTime parameter + scaffoldState.context.go( + Uri.parse( + '/date-time-route/2021-01-01T00:00:00.000?dateTimeField=invalid-date', + ).toString(), + ); + await tester.pumpAndSettle(); + expect(find.text('DateTimeRoute'), findsOneWidget); + expect(find.text('Param: 2021-01-01 00:00:00.000'), findsOneWidget); + expect(find.text('Query param: null'), findsOneWidget); - // Test invalid Double parameter - scaffoldState.context - .go(Uri.parse('/double-route/3.14?doubleField=invalid').toString()); - await tester.pumpAndSettle(); - expect(find.text('DoubleRoute'), findsOneWidget); - expect(find.text('Param: 3.14'), findsOneWidget); - expect(find.text('Query param: null'), findsOneWidget); - expect(find.text('Query param with default value: 1.0'), findsOneWidget); + // Test invalid Double parameter + scaffoldState.context.go( + Uri.parse('/double-route/3.14?doubleField=invalid').toString(), + ); + await tester.pumpAndSettle(); + expect(find.text('DoubleRoute'), findsOneWidget); + expect(find.text('Param: 3.14'), findsOneWidget); + expect(find.text('Query param: null'), findsOneWidget); + expect(find.text('Query param with default value: 1.0'), findsOneWidget); - // Test invalid Int parameter - scaffoldState.context - .go(Uri.parse('/int-route/65?intField=invalid').toString()); - await tester.pumpAndSettle(); - expect(find.text('IntRoute'), findsOneWidget); - expect(find.text('Param: 65'), findsOneWidget); - expect(find.text('Query param: null'), findsOneWidget); - expect(find.text('Query param with default value: 1'), findsOneWidget); + // Test invalid Int parameter + scaffoldState.context.go( + Uri.parse('/int-route/65?intField=invalid').toString(), + ); + await tester.pumpAndSettle(); + expect(find.text('IntRoute'), findsOneWidget); + expect(find.text('Param: 65'), findsOneWidget); + expect(find.text('Query param: null'), findsOneWidget); + expect(find.text('Query param with default value: 1'), findsOneWidget); - // Test invalid Uri parameter - scaffoldState.context.go( - Uri.parse('/uri-route/https%3A%2F%2Fdart.dev?uriField=invalid-uri') - .toString()); - await tester.pumpAndSettle(); - expect(find.text('UriRoute'), findsOneWidget); - expect(find.text('Param: https://dart.dev'), findsOneWidget); - expect(find.text('Query param: null'), findsOneWidget); + // Test invalid Uri parameter + scaffoldState.context.go( + Uri.parse( + '/uri-route/https%3A%2F%2Fdart.dev?uriField=invalid-uri', + ).toString(), + ); + await tester.pumpAndSettle(); + expect(find.text('UriRoute'), findsOneWidget); + expect(find.text('Param: https://dart.dev'), findsOneWidget); + expect(find.text('Query param: null'), findsOneWidget); - // Test invalid Enum parameter - scaffoldState.context.go( - Uri.parse('/enum-route/favorite-food?enum-field=invalid').toString()); - await tester.pumpAndSettle(); - expect(find.text('EnumRoute'), findsOneWidget); - expect(find.text('Query param: null'), findsOneWidget); - expect( + // Test invalid Enum parameter + scaffoldState.context.go( + Uri.parse('/enum-route/favorite-food?enum-field=invalid').toString(), + ); + await tester.pumpAndSettle(); + expect(find.text('EnumRoute'), findsOneWidget); + expect(find.text('Query param: null'), findsOneWidget); + expect( find.text('Query param with default value: PersonDetails.favoriteFood'), - findsOneWidget); + findsOneWidget, + ); - // Test invalid Iterable parameter - scaffoldState.context - .go(Uri.parse('/iterable-route?intListField=invalid').toString()); - await tester.pumpAndSettle(); - expect(find.text('IterableRoute'), findsOneWidget); - expect(find.text('/iterable-route'), findsOneWidget); - }); + // Test invalid Iterable parameter + scaffoldState.context.go( + Uri.parse('/iterable-route?intListField=invalid').toString(), + ); + await tester.pumpAndSettle(); + expect(find.text('IterableRoute'), findsOneWidget); + expect(find.text('/iterable-route'), findsOneWidget); + }, + ); } diff --git a/packages/go_router_builder/example/test/case_sensitivity_example_test.dart b/packages/go_router_builder/example/test/case_sensitivity_example_test.dart index c831789de2b..be388961b5c 100644 --- a/packages/go_router_builder/example/test/case_sensitivity_example_test.dart +++ b/packages/go_router_builder/example/test/case_sensitivity_example_test.dart @@ -8,39 +8,45 @@ import 'package:go_router_builder_example/case_sensitive_example.dart'; void main() { testWidgets( - 'It should navigate to the correct screen when the route is case sensitive and the path matches exactly', - (WidgetTester tester) async { - tester.platformDispatcher.defaultRouteNameTestValue = '/case-sensitive'; - await tester.pumpWidget(CaseSensitivityApp()); + 'It should navigate to the correct screen when the route is case sensitive and the path matches exactly', + (WidgetTester tester) async { + tester.platformDispatcher.defaultRouteNameTestValue = '/case-sensitive'; + await tester.pumpWidget(CaseSensitivityApp()); - expect(find.widgetWithText(AppBar, 'Case Sensitive'), findsOne); - }); + expect(find.widgetWithText(AppBar, 'Case Sensitive'), findsOne); + }, + ); testWidgets( - 'It should navigate to the correct screen when the route is not case sensitive and the path matches exactly', - (WidgetTester tester) async { - tester.platformDispatcher.defaultRouteNameTestValue = '/not-case-sensitive'; - await tester.pumpWidget(CaseSensitivityApp()); + 'It should navigate to the correct screen when the route is not case sensitive and the path matches exactly', + (WidgetTester tester) async { + tester.platformDispatcher.defaultRouteNameTestValue = + '/not-case-sensitive'; + await tester.pumpWidget(CaseSensitivityApp()); - expect(find.widgetWithText(AppBar, 'Not Case Sensitive'), findsOne); - }); + expect(find.widgetWithText(AppBar, 'Not Case Sensitive'), findsOne); + }, + ); testWidgets( - 'It should throw an error when the route is case sensitive and the path does not match', - (WidgetTester tester) async { - tester.platformDispatcher.defaultRouteNameTestValue = '/CASE-sensitive'; - await tester.pumpWidget(CaseSensitivityApp()); + 'It should throw an error when the route is case sensitive and the path does not match', + (WidgetTester tester) async { + tester.platformDispatcher.defaultRouteNameTestValue = '/CASE-sensitive'; + await tester.pumpWidget(CaseSensitivityApp()); - expect(find.widgetWithText(AppBar, 'Case Sensitive'), findsNothing); - expect(find.text('Page Not Found'), findsOne); - }); + expect(find.widgetWithText(AppBar, 'Case Sensitive'), findsNothing); + expect(find.text('Page Not Found'), findsOne); + }, + ); testWidgets( - 'It should navigate to the correct screen when the route is not case sensitive and the path case does not match', - (WidgetTester tester) async { - tester.platformDispatcher.defaultRouteNameTestValue = '/NOT-case-sensitive'; - await tester.pumpWidget(CaseSensitivityApp()); - - expect(find.widgetWithText(AppBar, 'Not Case Sensitive'), findsOne); - }); + 'It should navigate to the correct screen when the route is not case sensitive and the path case does not match', + (WidgetTester tester) async { + tester.platformDispatcher.defaultRouteNameTestValue = + '/NOT-case-sensitive'; + await tester.pumpWidget(CaseSensitivityApp()); + + expect(find.widgetWithText(AppBar, 'Not Case Sensitive'), findsOne); + }, + ); } diff --git a/packages/go_router_builder/example/test/location_test.dart b/packages/go_router_builder/example/test/location_test.dart index fc33e931f59..c997d5e3c98 100644 --- a/packages/go_router_builder/example/test/location_test.dart +++ b/packages/go_router_builder/example/test/location_test.dart @@ -16,9 +16,7 @@ void main() { // https://github.com/flutter/flutter/issues/127825. final Set doubleSetField = {}; expect( - IterableRouteWithDefaultValues( - doubleSetField: doubleSetField, - ).location, + IterableRouteWithDefaultValues(doubleSetField: doubleSetField).location, '/iterable-route-with-default-values', ); @@ -33,9 +31,7 @@ void main() { // https://github.com/flutter/flutter/issues/127825. final Set intSetField = {0, 1}; expect( - IterableRouteWithDefaultValues( - intSetField: intSetField, - ).location, + IterableRouteWithDefaultValues(intSetField: intSetField).location, '/iterable-route-with-default-values', ); diff --git a/packages/go_router_builder/example/test/on_exit_example_test.dart b/packages/go_router_builder/example/test/on_exit_example_test.dart index e41adb0c618..9220ea19149 100644 --- a/packages/go_router_builder/example/test/on_exit_example_test.dart +++ b/packages/go_router_builder/example/test/on_exit_example_test.dart @@ -7,8 +7,9 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:go_router_builder_example/on_exit_example.dart'; void main() { - testWidgets('It should trigger the on exit when leaving the route', - (WidgetTester tester) async { + testWidgets('It should trigger the on exit when leaving the route', ( + WidgetTester tester, + ) async { await tester.pumpWidget(App()); expect(find.byType(HomeScreen), findsOne); diff --git a/packages/go_router_builder/example/test/simple_example_test.dart b/packages/go_router_builder/example/test/simple_example_test.dart index 80c51864740..19d3168f381 100644 --- a/packages/go_router_builder/example/test/simple_example_test.dart +++ b/packages/go_router_builder/example/test/simple_example_test.dart @@ -8,8 +8,9 @@ import 'package:go_router_builder_example/shared/data.dart'; import 'package:go_router_builder_example/simple_example.dart'; void main() { - testWidgets('App starts on HomeScreen and displays families', - (WidgetTester tester) async { + testWidgets('App starts on HomeScreen and displays families', ( + WidgetTester tester, + ) async { await tester.pumpWidget(App()); expect(find.byType(HomeScreen), findsOneWidget); expect(find.byType(ListTile), findsNWidgets(familyData.length)); diff --git a/packages/go_router_builder/example/test/stateful_shell_route_test.dart b/packages/go_router_builder/example/test/stateful_shell_route_test.dart index f885e54c531..beb89c1e1f2 100644 --- a/packages/go_router_builder/example/test/stateful_shell_route_test.dart +++ b/packages/go_router_builder/example/test/stateful_shell_route_test.dart @@ -6,8 +6,9 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:go_router_builder_example/stateful_shell_route_example.dart'; void main() { - testWidgets('Navigate between section A and section B', - (WidgetTester tester) async { + testWidgets('Navigate between section A and section B', ( + WidgetTester tester, + ) async { await tester.pumpWidget(App()); expect(find.text('Details for A - Counter: 0'), findsOneWidget); From e59cfc88ad2c1c5043795a1148cc785a2a675217 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 15 Aug 2025 09:41:52 -0400 Subject: [PATCH 2/3] [go_router_builder] Adjust generated whitespace The Dart 3.7+ formatter does not remove all blank lines in function calls split across multile lines, so the generated+formatted output no longer matched expetations once the example app was changed to use a minimum SDK of 3.7. This updates the example app, and changes the code generator such that running the new formatter on the output has the same results as it did with the previous formatter. Unblocks https://github.com/flutter/packages/pull/9816 --- packages/go_router_builder/CHANGELOG.md | 4 ++++ .../go_router_builder/lib/src/route_config.dart | 16 ++++++---------- packages/go_router_builder/pubspec.yaml | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 8004affe809..c47f328b9be 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.1 + +- Changes generated whitespace for better compatibility with new Dart formatter. + ## 3.2.0 - Adds support for`extension type`. diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index b15f2b3539c..7405028bcd9 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -477,12 +477,11 @@ mixin $_mixinName on GoRouteData { String get factorConstructorParameters => 'factory: $_mixinName._fromState,'; @override - String get routeConstructorParameters => ''' - path: ${escapeDartString(path)}, - ${name != null ? 'name: ${escapeDartString(name!)},' : ''} - ${caseSensitive ? '' : 'caseSensitive: $caseSensitive,'} - ${parentNavigatorKey == null ? '' : 'parentNavigatorKey: $parentNavigatorKey,'} -'''; + String get routeConstructorParameters => + 'path: ${escapeDartString(path)},' + '${name != null ? 'name: ${escapeDartString(name!)},' : ''}' + '${caseSensitive ? '' : 'caseSensitive: $caseSensitive,'}' + '${parentNavigatorKey == null ? '' : 'parentNavigatorKey: $parentNavigatorKey,'}'; @override String get routeDataClassName => 'GoRouteData'; @@ -765,10 +764,7 @@ ${_generateChildrenGetterName(routeDataClassName)}: [${_children.map((RouteBaseC return ''' $routeDataClassName.$dataConvertionFunctionName( - $routeConstructorParameters - $factorConstructorParameters - $routesBit - ) + $routeConstructorParameters $factorConstructorParameters $routesBit) '''; } diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index cf44bfb70a2..7825f7f28b4 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: 3.2.0 +version: 3.2.1 repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22 From c6f1dc98c70ae7054a9a186d5aec295301471478 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 15 Aug 2025 10:25:24 -0400 Subject: [PATCH 3/3] Update excerpts --- packages/go_router_builder/README.md | 32 +++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/go_router_builder/README.md b/packages/go_router_builder/README.md index 1a683bb4784..643a664b6fa 100644 --- a/packages/go_router_builder/README.md +++ b/packages/go_router_builder/README.md @@ -103,9 +103,7 @@ The tree of routes is defined as an attribute on each of the top-level routes: @TypedGoRoute( path: '/', routes: >[ - TypedGoRoute( - path: 'family/:fid', - ), + TypedGoRoute(path: 'family/:fid'), ], ) class HomeRoute extends GoRouteData with _$HomeRoute { @@ -200,8 +198,9 @@ a return value. The generated routes also follow this functionality. ```dart -final bool? result = - await const FamilyRoute(fid: 'John').push(context); +final bool? result = await const FamilyRoute( + fid: 'John', +).push(context); ``` ## Query parameters @@ -376,10 +375,7 @@ class MyMaterialRouteWithKey extends GoRouteData with _$MyMaterialRouteWithKey { static const LocalKey _key = ValueKey('my-route-with-key'); @override MaterialPage buildPage(BuildContext context, GoRouterState state) { - return const MaterialPage( - key: _key, - child: MyPage(), - ); + return const MaterialPage(key: _key, child: MyPage()); } } ``` @@ -398,12 +394,17 @@ class FancyRoute extends GoRouteData with _$FancyRoute { GoRouterState state, ) { return CustomTransitionPage( - key: state.pageKey, - child: const MyPage(), - transitionsBuilder: (BuildContext context, Animation animation, - Animation secondaryAnimation, Widget child) { - return RotationTransition(turns: animation, child: child); - }); + key: state.pageKey, + child: const MyPage(), + transitionsBuilder: ( + BuildContext context, + Animation animation, + Animation secondaryAnimation, + Widget child, + ) { + return RotationTransition(turns: animation, child: child); + }, + ); } } ``` @@ -449,6 +450,7 @@ class MyGoRouteData extends GoRouteData with _$MyGoRouteData { @override Widget build(BuildContext context, GoRouterState state) => const MyPage(); } + ``` An example is available [here](https://github.com/flutter/packages/blob/main/packages/go_router_builder/example/lib/shell_route_with_keys_example.dart).