diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 25a2fb369432..419ac724b382 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,11 @@ +## 4.3.2 + +* Fixes generated routes so `onExit` is only enabled when the route data class overrides it, + preventing spurious Navigator assertion crashes during rapid back navigation + (flutter/flutter#189503). +* Bumps the documented and example minimum `go_router` constraint to `^17.3.0` + to require the `hasOverriddenOnExit` route helper. + ## 4.3.1 * Updates minimum supported SDK version to Flutter 3.38/Dart 3.10. diff --git a/packages/go_router_builder/README.md b/packages/go_router_builder/README.md index 99d298a489d4..308861188b05 100644 --- a/packages/go_router_builder/README.md +++ b/packages/go_router_builder/README.md @@ -8,12 +8,12 @@ To use `go_router_builder`, you need to have the following dependencies in ```yaml dependencies: # ...along with your other dependencies - go_router: ^16.2.0 + go_router: ^17.3.0 dev_dependencies: # ...along with your other dev-dependencies build_runner: ^2.6.0 - go_router_builder: ^4.0.1 + go_router_builder: ^4.3.2 ``` ### Source code 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 3fd882af5efd..c8ef4167ef92 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 @@ -12,50 +12,62 @@ List get $appRoutes => [$allTypesBaseRoute]; RouteBase get $allTypesBaseRoute => GoRouteData.$route( path: '/', + hasOverriddenOnExit: false, factory: $AllTypesBaseRoute._fromState, routes: [ GoRouteData.$route( path: 'big-int-route/:requiredBigIntField', + hasOverriddenOnExit: false, factory: $BigIntExtensionRoute._fromState, ), GoRouteData.$route( path: 'bool-route/:requiredBoolField', + hasOverriddenOnExit: false, factory: $BoolExtensionRoute._fromState, ), GoRouteData.$route( path: 'date-time-route/:requiredDateTimeField', + hasOverriddenOnExit: false, factory: $DateTimeExtensionRoute._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', + hasOverriddenOnExit: false, factory: $DoubleExtensionRoute._fromState, ), GoRouteData.$route( path: 'int-route/:requiredIntField', + hasOverriddenOnExit: false, factory: $IntExtensionRoute._fromState, ), GoRouteData.$route( path: 'num-route/:requiredNumField', + hasOverriddenOnExit: false, factory: $NumExtensionRoute._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', + hasOverriddenOnExit: false, factory: $DoubleExtensionRoute._fromState, ), GoRouteData.$route( path: 'enum-route/:requiredEnumField', + hasOverriddenOnExit: false, factory: $EnumExtensionRoute._fromState, ), GoRouteData.$route( path: 'enhanced-enum-route/:requiredEnumField', + hasOverriddenOnExit: false, factory: $EnhancedEnumExtensionRoute._fromState, ), GoRouteData.$route( path: 'string-route/:requiredStringField', + hasOverriddenOnExit: false, factory: $StringExtensionRoute._fromState, ), GoRouteData.$route( path: 'uri-route/:requiredUriField', + hasOverriddenOnExit: false, factory: $UriExtensionRoute._fromState, ), ], 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 81f90bb61d69..d06b99c7488c 100644 --- a/packages/go_router_builder/example/lib/all_types.g.dart +++ b/packages/go_router_builder/example/lib/all_types.g.dart @@ -12,58 +12,72 @@ List get $appRoutes => [$allTypesBaseRoute]; RouteBase get $allTypesBaseRoute => GoRouteData.$route( path: '/', + hasOverriddenOnExit: false, factory: $AllTypesBaseRoute._fromState, routes: [ GoRouteData.$route( path: 'big-int-route/:requiredBigIntField', + hasOverriddenOnExit: false, factory: $BigIntRoute._fromState, ), GoRouteData.$route( path: 'bool-route/:requiredBoolField', + hasOverriddenOnExit: false, factory: $BoolRoute._fromState, ), GoRouteData.$route( path: 'date-time-route/:requiredDateTimeField', + hasOverriddenOnExit: false, factory: $DateTimeRoute._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', + hasOverriddenOnExit: false, factory: $DoubleRoute._fromState, ), GoRouteData.$route( path: 'int-route/:requiredIntField', + hasOverriddenOnExit: false, factory: $IntRoute._fromState, ), GoRouteData.$route( path: 'num-route/:requiredNumField', + hasOverriddenOnExit: false, factory: $NumRoute._fromState, ), GoRouteData.$route( path: 'double-route/:requiredDoubleField', + hasOverriddenOnExit: false, factory: $DoubleRoute._fromState, ), GoRouteData.$route( path: 'enum-route/:requiredEnumField', + hasOverriddenOnExit: false, factory: $EnumRoute._fromState, ), GoRouteData.$route( path: 'enhanced-enum-route/:requiredEnumField', + hasOverriddenOnExit: false, factory: $EnhancedEnumRoute._fromState, ), GoRouteData.$route( path: 'string-route/:requiredStringField', + hasOverriddenOnExit: false, factory: $StringRoute._fromState, ), GoRouteData.$route( path: 'uri-route/:requiredUriField', + hasOverriddenOnExit: false, factory: $UriRoute._fromState, ), GoRouteData.$route( path: 'iterable-route', + hasOverriddenOnExit: false, factory: $IterableRoute._fromState, ), GoRouteData.$route( path: 'iterable-route-with-default-values', + hasOverriddenOnExit: false, factory: $IterableRouteWithDefaultValues._fromState, ), ], 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 0d1307641d31..0f1b39e6ef8e 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 @@ -12,6 +12,7 @@ List get $appRoutes => [$caseSensitiveRoute, $notCaseSensitiveRoute]; RouteBase get $caseSensitiveRoute => GoRouteData.$route( path: '/case-sensitive', + hasOverriddenOnExit: false, factory: $CaseSensitiveRoute._fromState, ); @@ -39,6 +40,7 @@ mixin $CaseSensitiveRoute on GoRouteData { RouteBase get $notCaseSensitiveRoute => GoRouteData.$route( path: '/not-case-sensitive', caseSensitive: false, + hasOverriddenOnExit: false, factory: $NotCaseSensitiveRoute._fromState, ); diff --git a/packages/go_router_builder/example/lib/custom_encoder_example.g.dart b/packages/go_router_builder/example/lib/custom_encoder_example.g.dart index ab002c500782..df7c1cdb46fc 100644 --- a/packages/go_router_builder/example/lib/custom_encoder_example.g.dart +++ b/packages/go_router_builder/example/lib/custom_encoder_example.g.dart @@ -13,9 +13,14 @@ List get $appRoutes => [$homeRoute]; RouteBase get $homeRoute => GoRouteData.$route( path: '/', name: 'Home', + hasOverriddenOnExit: false, factory: $HomeRoute._fromState, routes: [ - GoRouteData.$route(path: 'encoded', factory: $EncodedRoute._fromState), + GoRouteData.$route( + path: 'encoded', + hasOverriddenOnExit: false, + factory: $EncodedRoute._fromState, + ), ], ); 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 ee366a688a38..ada4b353626f 100644 --- a/packages/go_router_builder/example/lib/extra_example.g.dart +++ b/packages/go_router_builder/example/lib/extra_example.g.dart @@ -16,6 +16,7 @@ List get $appRoutes => [ RouteBase get $requiredExtraRoute => GoRouteData.$route( path: '/requiredExtra', + hasOverriddenOnExit: false, factory: $RequiredExtraRoute._fromState, ); @@ -46,6 +47,7 @@ mixin $RequiredExtraRoute on GoRouteData { RouteBase get $optionalExtraRoute => GoRouteData.$route( path: '/optionalExtra', + hasOverriddenOnExit: false, factory: $OptionalExtraRoute._fromState, ); @@ -74,8 +76,11 @@ 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', + hasOverriddenOnExit: false, + factory: $SplashRoute._fromState, +); mixin $SplashRoute on GoRouteData { static SplashRoute _fromState(GoRouterState state) => const SplashRoute(); diff --git a/packages/go_router_builder/example/lib/go_relative.g.dart b/packages/go_router_builder/example/lib/go_relative.g.dart index ef565d171a96..cce2481c1059 100644 --- a/packages/go_router_builder/example/lib/go_relative.g.dart +++ b/packages/go_router_builder/example/lib/go_relative.g.dart @@ -12,18 +12,22 @@ List get $appRoutes => [$homeRoute]; RouteBase get $homeRoute => GoRouteData.$route( path: '/', + hasOverriddenOnExit: false, factory: $HomeRoute._fromState, routes: [ GoRouteData.$route( path: '/dashboard', + hasOverriddenOnExit: false, factory: $DashboardRoute._fromState, routes: [ RelativeGoRouteData.$route( path: 'details/:detailId', + hasOverriddenOnExit: false, factory: $DetailsRoute._fromState, routes: [ RelativeGoRouteData.$route( path: 'settings/:settingId', + hasOverriddenOnExit: false, factory: $SettingsRoute._fromState, ), ], @@ -32,10 +36,12 @@ RouteBase get $homeRoute => GoRouteData.$route( ), RelativeGoRouteData.$route( path: 'details/:detailId', + hasOverriddenOnExit: false, factory: $DetailsRoute._fromState, routes: [ RelativeGoRouteData.$route( path: 'settings/:settingId', + hasOverriddenOnExit: false, factory: $SettingsRoute._fromState, ), ], diff --git a/packages/go_router_builder/example/lib/json_example.g.dart b/packages/go_router_builder/example/lib/json_example.g.dart index 99600db150ef..cba72075d780 100644 --- a/packages/go_router_builder/example/lib/json_example.g.dart +++ b/packages/go_router_builder/example/lib/json_example.g.dart @@ -13,8 +13,15 @@ List get $appRoutes => [$homeRoute]; RouteBase get $homeRoute => GoRouteData.$route( path: '/', name: 'Home', + hasOverriddenOnExit: false, factory: $HomeRoute._fromState, - routes: [GoRouteData.$route(path: 'json', factory: $JsonRoute._fromState)], + routes: [ + GoRouteData.$route( + path: 'json', + hasOverriddenOnExit: false, + factory: $JsonRoute._fromState, + ), + ], ); mixin $HomeRoute on GoRouteData { diff --git a/packages/go_router_builder/example/lib/json_nested_example.g.dart b/packages/go_router_builder/example/lib/json_nested_example.g.dart index 18411ebc9a7c..8cafa7b08c2f 100644 --- a/packages/go_router_builder/example/lib/json_nested_example.g.dart +++ b/packages/go_router_builder/example/lib/json_nested_example.g.dart @@ -13,8 +13,15 @@ List get $appRoutes => [$homeRoute]; RouteBase get $homeRoute => GoRouteData.$route( path: '/', name: 'Home', + hasOverriddenOnExit: false, factory: $HomeRoute._fromState, - routes: [GoRouteData.$route(path: 'json', factory: $JsonRoute._fromState)], + routes: [ + GoRouteData.$route( + path: 'json', + hasOverriddenOnExit: false, + factory: $JsonRoute._fromState, + ), + ], ); mixin $HomeRoute on GoRouteData { diff --git a/packages/go_router_builder/example/lib/main.g.dart b/packages/go_router_builder/example/lib/main.g.dart index fc044ef4186b..ae2fd8e288a1 100644 --- a/packages/go_router_builder/example/lib/main.g.dart +++ b/packages/go_router_builder/example/lib/main.g.dart @@ -12,18 +12,22 @@ List get $appRoutes => [$homeRoute, $loginRoute]; RouteBase get $homeRoute => GoRouteData.$route( path: '/', + hasOverriddenOnExit: false, factory: $HomeRoute._fromState, routes: [ GoRouteData.$route( path: 'family/:fid', + hasOverriddenOnExit: false, factory: $FamilyRoute._fromState, routes: [ GoRouteData.$route( path: 'person/:pid', + hasOverriddenOnExit: false, factory: $PersonRoute._fromState, routes: [ GoRouteData.$route( path: 'details/:details', + hasOverriddenOnExit: false, factory: $PersonDetailsRoute._fromState, ), ], @@ -32,6 +36,7 @@ RouteBase get $homeRoute => GoRouteData.$route( ), GoRouteData.$route( path: 'family-count/:count', + hasOverriddenOnExit: false, factory: $FamilyCountRoute._fromState, ), ], @@ -176,8 +181,11 @@ 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', + hasOverriddenOnExit: false, + factory: $LoginRoute._fromState, +); mixin $LoginRoute on GoRouteData { static LoginRoute _fromState(GoRouterState state) => 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 e108c912ab38..7f9b4420112e 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 @@ -12,9 +12,14 @@ List get $appRoutes => [$homeRoute]; RouteBase get $homeRoute => GoRouteData.$route( path: '/', + hasOverriddenOnExit: false, factory: $HomeRoute._fromState, routes: [ - GoRouteData.$route(path: 'sub-route', factory: $SubRoute._fromState), + GoRouteData.$route( + path: 'sub-route', + hasOverriddenOnExit: true, + factory: $SubRoute._fromState, + ), ], ); 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 9cfd76b05eb4..c9471e626a2c 100644 --- a/packages/go_router_builder/example/lib/readme_excerpts.g.dart +++ b/packages/go_router_builder/example/lib/readme_excerpts.g.dart @@ -23,9 +23,14 @@ List get $appRoutes => [ RouteBase get $homeRoute => GoRouteData.$route( path: '/', + hasOverriddenOnExit: false, factory: $HomeRoute._fromState, routes: [ - GoRouteData.$route(path: 'family/:fid', factory: $FamilyRoute._fromState), + GoRouteData.$route( + path: 'family/:fid', + hasOverriddenOnExit: false, + factory: $FamilyRoute._fromState, + ), ], ); @@ -73,8 +78,11 @@ 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', + hasOverriddenOnExit: false, + factory: $LoginRoute._fromState, +); mixin $LoginRoute on GoRouteData { static LoginRoute _fromState(GoRouterState state) => @@ -102,8 +110,11 @@ 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', + hasOverriddenOnExit: false, + factory: $MyRoute._fromState, +); mixin $MyRoute on GoRouteData { static MyRoute _fromState(GoRouterState state) => MyRoute( @@ -138,6 +149,7 @@ mixin $MyRoute on GoRouteData { RouteBase get $personRouteWithExtra => GoRouteData.$route( path: '/person', + hasOverriddenOnExit: false, factory: $PersonRouteWithExtra._fromState, ); @@ -168,6 +180,7 @@ mixin $PersonRouteWithExtra on GoRouteData { RouteBase get $hotdogRouteWithEverything => GoRouteData.$route( path: '/:ketchup', + hasOverriddenOnExit: false, factory: $HotdogRouteWithEverything._fromState, ); @@ -214,8 +227,11 @@ bool _$boolConverter(String value) { } } -RouteBase get $booksRoute => - GoRouteData.$route(path: '/books', factory: $BooksRoute._fromState); +RouteBase get $booksRoute => GoRouteData.$route( + path: '/books', + hasOverriddenOnExit: false, + factory: $BooksRoute._fromState, +); mixin $BooksRoute on GoRouteData { static BooksRoute _fromState(GoRouterState state) => BooksRoute( @@ -274,6 +290,7 @@ extension on Map { RouteBase get $myMaterialRouteWithKey => GoRouteData.$route( path: '/my-material-route-with-key', + hasOverriddenOnExit: false, factory: $MyMaterialRouteWithKey._fromState, ); @@ -298,8 +315,11 @@ 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', + hasOverriddenOnExit: false, + factory: $FancyRoute._fromState, +); mixin $FancyRoute on GoRouteData { static FancyRoute _fromState(GoRouterState state) => const FancyRoute(); @@ -328,6 +348,7 @@ RouteBase get $myShellRouteData => ShellRouteData.$route( GoRouteData.$route( path: 'my-go-route', parentNavigatorKey: MyGoRouteData.$parentNavigatorKey, + hasOverriddenOnExit: false, factory: $MyGoRouteData._fromState, ), ], @@ -360,6 +381,7 @@ mixin $MyGoRouteData on GoRouteData { RouteBase get $detailsRoute => RelativeGoRouteData.$route( path: 'details', + hasOverriddenOnExit: false, factory: $DetailsRoute._fromState, ); 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 cac7b3d666ab..354b4ba85203 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 @@ -13,8 +13,16 @@ 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), + GoRouteData.$route( + path: '/foo', + hasOverriddenOnExit: false, + factory: $FooRouteData._fromState, + ), + GoRouteData.$route( + path: '/bar', + hasOverriddenOnExit: false, + factory: $BarRouteData._fromState, + ), ], ); @@ -63,8 +71,11 @@ 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', + hasOverriddenOnExit: false, + factory: $LoginRoute._fromState, +); mixin $LoginRoute on GoRouteData { static LoginRoute _fromState(GoRouterState state) => const LoginRoute(); 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 8c09a9983e29..8fa2c5c49448 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 @@ -14,14 +14,20 @@ RouteBase get $myShellRouteData => ShellRouteData.$route( navigatorKey: MyShellRouteData.$navigatorKey, factory: $MyShellRouteDataExtension._fromState, routes: [ - GoRouteData.$route(path: '/home', factory: $HomeRouteData._fromState), + GoRouteData.$route( + path: '/home', + hasOverriddenOnExit: false, + factory: $HomeRouteData._fromState, + ), GoRouteData.$route( path: '/users', + hasOverriddenOnExit: false, factory: $UsersRouteData._fromState, routes: [ GoRouteData.$route( path: ':id', parentNavigatorKey: UserRouteData.$parentNavigatorKey, + hasOverriddenOnExit: false, factory: $UserRouteData._fromState, ), ], 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 b52f89783f87..336df634f33f 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 @@ -14,12 +14,21 @@ RouteBase get $myShellRouteData => ShellRouteData.$route( observers: MyShellRouteData.$observers, factory: $MyShellRouteDataExtension._fromState, routes: [ - GoRouteData.$route(path: '/home', factory: $HomeRouteData._fromState), + GoRouteData.$route( + path: '/home', + hasOverriddenOnExit: false, + factory: $HomeRouteData._fromState, + ), GoRouteData.$route( path: '/users', + hasOverriddenOnExit: false, factory: $UsersRouteData._fromState, routes: [ - GoRouteData.$route(path: ':id', factory: $UserRouteData._fromState), + GoRouteData.$route( + path: ':id', + hasOverriddenOnExit: false, + factory: $UserRouteData._fromState, + ), ], ), ], diff --git a/packages/go_router_builder/example/lib/simple_example.g.dart b/packages/go_router_builder/example/lib/simple_example.g.dart index 376c28ded398..a475d95b2fe2 100644 --- a/packages/go_router_builder/example/lib/simple_example.g.dart +++ b/packages/go_router_builder/example/lib/simple_example.g.dart @@ -13,10 +13,12 @@ List get $appRoutes => [$homeRoute]; RouteBase get $homeRoute => GoRouteData.$route( path: '/', name: 'Home', + hasOverriddenOnExit: false, factory: $HomeRoute._fromState, routes: [ GoRouteData.$route( path: 'family/:familyId', + hasOverriddenOnExit: false, factory: $FamilyRoute._fromState, ), ], 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 ecd05a1b79c4..f7748149e284 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 @@ -19,6 +19,7 @@ RouteBase get $myShellRouteData => StatefulShellRouteData.$route( routes: [ GoRouteData.$route( path: '/detailsA', + hasOverriddenOnExit: false, factory: $DetailsARouteData._fromState, ), ], @@ -29,6 +30,7 @@ RouteBase get $myShellRouteData => StatefulShellRouteData.$route( routes: [ GoRouteData.$route( path: '/detailsB', + hasOverriddenOnExit: false, factory: $DetailsBRouteData._fromState, ), ], 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 690ffbdf9c67..cbcff9c50538 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 @@ -15,7 +15,11 @@ RouteBase get $mainShellRouteData => StatefulShellRouteData.$route( branches: [ StatefulShellBranchData.$branch( routes: [ - GoRouteData.$route(path: '/home', factory: $HomeRouteData._fromState), + GoRouteData.$route( + path: '/home', + hasOverriddenOnExit: false, + factory: $HomeRouteData._fromState, + ), ], ), StatefulShellBranchData.$branch( @@ -23,6 +27,7 @@ RouteBase get $mainShellRouteData => StatefulShellRouteData.$route( routes: [ GoRouteData.$route( path: '/notifications/:section', + hasOverriddenOnExit: false, factory: $NotificationsRouteData._fromState, ), ], @@ -31,6 +36,7 @@ RouteBase get $mainShellRouteData => StatefulShellRouteData.$route( routes: [ GoRouteData.$route( path: '/orders', + hasOverriddenOnExit: false, factory: $OrdersRouteData._fromState, ), ], diff --git a/packages/go_router_builder/example/lib/typed_query_parameter_example.g.dart b/packages/go_router_builder/example/lib/typed_query_parameter_example.g.dart index d4c30ac00c85..c6f37a9c9baa 100644 --- a/packages/go_router_builder/example/lib/typed_query_parameter_example.g.dart +++ b/packages/go_router_builder/example/lib/typed_query_parameter_example.g.dart @@ -10,8 +10,11 @@ part of 'typed_query_parameter_example.dart'; List get $appRoutes => [$intRoute]; -RouteBase get $intRoute => - GoRouteData.$route(path: '/int-route', factory: $IntRoute._fromState); +RouteBase get $intRoute => GoRouteData.$route( + path: '/int-route', + hasOverriddenOnExit: false, + factory: $IntRoute._fromState, +); mixin $IntRoute on GoRouteData { static IntRoute _fromState(GoRouterState state) => IntRoute( diff --git a/packages/go_router_builder/example/pubspec.yaml b/packages/go_router_builder/example/pubspec.yaml index 432af21ad4c0..0160489c2070 100644 --- a/packages/go_router_builder/example/pubspec.yaml +++ b/packages/go_router_builder/example/pubspec.yaml @@ -9,7 +9,7 @@ dependencies: collection: ^1.15.0 flutter: sdk: flutter - go_router: ^17.2.0 + go_router: ^17.3.0 provider: 6.0.5 dev_dependencies: diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index 7de0c2dcb2a7..a5079914a181 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -190,6 +190,18 @@ mixin _GoRouteMixin on RouteBaseConfig { late final Set _pathParams = pathParametersFromPattern(_basePathForLocation); + bool get _hasOverriddenOnExit { + final MethodElement? onExit = routeDataClass.thisType.lookUpMethod( + 'onExit', + routeDataClass.library, + ); + final String? enclosingName = onExit?.enclosingElement?.displayName; + return onExit != null && + enclosingName != '_GoRouteDataBase' && + enclosingName != 'GoRouteData' && + enclosingName != 'RelativeGoRouteData'; + } + // construct path bits using parent bits // if there are any queryParam objects, add in the `queryParam` bits String get _locationArgs { @@ -474,7 +486,8 @@ mixin $_mixinName on $routeDataClassName { 'path: ${escapeDartString(path)},' '${name != null ? 'name: ${escapeDartString(name!)},' : ''}' '${caseSensitive ? '' : 'caseSensitive: $caseSensitive,'}' - '${parentNavigatorKey == null ? '' : 'parentNavigatorKey: $parentNavigatorKey,'}'; + '${parentNavigatorKey == null ? '' : 'parentNavigatorKey: $parentNavigatorKey,'}' + 'hasOverriddenOnExit: $_hasOverriddenOnExit,'; @override String get routeDataClassName => 'GoRouteData'; @@ -550,7 +563,8 @@ mixin $_mixinName on $routeDataClassName { String get routeConstructorParameters => 'path: ${escapeDartString(path)},' '${caseSensitive ? '' : 'caseSensitive: $caseSensitive,'}' - '${parentNavigatorKey == null ? '' : 'parentNavigatorKey: $parentNavigatorKey,'}'; + '${parentNavigatorKey == null ? '' : 'parentNavigatorKey: $parentNavigatorKey,'}' + 'hasOverriddenOnExit: $_hasOverriddenOnExit,'; @override String get routeDataClassName => 'RelativeGoRouteData'; diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 71c35d7b754b..5ac6422dd284 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: 4.3.1 +version: 4.3.2 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 @@ -27,7 +27,7 @@ dev_dependencies: dart_style: ">=2.3.7 <4.0.0" flutter: sdk: flutter - go_router: ^17.2.0 + go_router: ^17.3.0 leak_tracker_flutter_testing: ">=3.0.0" package_config: ^2.1.1 pub_semver: ^2.1.5 diff --git a/packages/go_router_builder/test_inputs/case_sensitivity.dart.expect b/packages/go_router_builder/test_inputs/case_sensitivity.dart.expect index 97cc21a21832..d938475293a4 100644 --- a/packages/go_router_builder/test_inputs/case_sensitivity.dart.expect +++ b/packages/go_router_builder/test_inputs/case_sensitivity.dart.expect @@ -1,16 +1,15 @@ RouteBase get $caseSensitiveRoute => GoRouteData.$route( - path: '/case-sensitive-route', - factory: $CaseSensitiveRoute._fromState, - ); + path: '/case-sensitive-route', + hasOverriddenOnExit: false, + factory: $CaseSensitiveRoute._fromState, +); mixin $CaseSensitiveRoute on GoRouteData { static CaseSensitiveRoute _fromState(GoRouterState state) => CaseSensitiveRoute(); @override - String get location => GoRouteData.$location( - '/case-sensitive-route', - ); + String get location => GoRouteData.$location('/case-sensitive-route'); @override void go(BuildContext context) => context.go(location); @@ -27,19 +26,18 @@ mixin $CaseSensitiveRoute on GoRouteData { } RouteBase get $notCaseSensitiveRoute => GoRouteData.$route( - path: '/not-case-sensitive-route', - caseSensitive: false, - factory: $NotCaseSensitiveRoute._fromState, - ); + path: '/not-case-sensitive-route', + caseSensitive: false, + hasOverriddenOnExit: false, + factory: $NotCaseSensitiveRoute._fromState, +); mixin $NotCaseSensitiveRoute on GoRouteData { static NotCaseSensitiveRoute _fromState(GoRouterState state) => NotCaseSensitiveRoute(); @override - String get location => GoRouteData.$location( - '/not-case-sensitive-route', - ); + String get location => GoRouteData.$location('/not-case-sensitive-route'); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/custom_encoder.dart.expect b/packages/go_router_builder/test_inputs/custom_encoder.dart.expect index d37b9cdc6a17..cdfcc7e7397a 100644 --- a/packages/go_router_builder/test_inputs/custom_encoder.dart.expect +++ b/packages/go_router_builder/test_inputs/custom_encoder.dart.expect @@ -1,5 +1,6 @@ RouteBase get $customParameterRoute => GoRouteData.$route( path: '/default-value-route', + hasOverriddenOnExit: false, factory: $CustomParameterRoute._fromState, ); @@ -33,6 +34,7 @@ mixin $CustomParameterRoute on GoRouteData { RouteBase get $customParameterComplexRoute => GoRouteData.$route( path: '/:id/', + hasOverriddenOnExit: false, factory: $CustomParameterComplexRoute._fromState, ); @@ -47,10 +49,9 @@ mixin $CustomParameterComplexRoute on GoRouteData { .cast() .toList() ?? const [], - enumTest: - _$EnumTestEnumMap._$fromName( - fromBase64(state.uri.queryParameters['enum-test']!), - )!, + enumTest: _$EnumTestEnumMap._$fromName( + fromBase64(state.uri.queryParameters['enum-test']!), + )!, ); CustomParameterComplexRoute get _self => this as CustomParameterComplexRoute; diff --git a/packages/go_router_builder/test_inputs/default_value.dart.expect b/packages/go_router_builder/test_inputs/default_value.dart.expect index 50ef48849324..64e82f35839f 100644 --- a/packages/go_router_builder/test_inputs/default_value.dart.expect +++ b/packages/go_router_builder/test_inputs/default_value.dart.expect @@ -1,24 +1,22 @@ RouteBase get $defaultValueRoute => GoRouteData.$route( - path: '/default-value-route', - factory: $DefaultValueRoute._fromState, - ); + path: '/default-value-route', + hasOverriddenOnExit: false, + factory: $DefaultValueRoute._fromState, +); mixin $DefaultValueRoute on GoRouteData { static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute( - param: - _$convertMapValue('param', state.uri.queryParameters, int.parse) ?? - 0, - ); + param: + _$convertMapValue('param', state.uri.queryParameters, int.parse) ?? 0, + ); DefaultValueRoute get _self => this as DefaultValueRoute; @override String get location => GoRouteData.$location( - '/default-value-route', - queryParams: { - if (_self.param != 0) 'param': _self.param.toString(), - }, - ); + '/default-value-route', + queryParams: {if (_self.param != 0) 'param': _self.param.toString()}, + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/enum_parameter.dart.expect b/packages/go_router_builder/test_inputs/enum_parameter.dart.expect index 218033aaee4d..7f67968e1c1c 100644 --- a/packages/go_router_builder/test_inputs/enum_parameter.dart.expect +++ b/packages/go_router_builder/test_inputs/enum_parameter.dart.expect @@ -1,19 +1,19 @@ RouteBase get $enumParam => GoRouteData.$route( - path: '/:y', - factory: $EnumParam._fromState, - ); + path: '/:y', + hasOverriddenOnExit: false, + factory: $EnumParam._fromState, +); mixin $EnumParam on GoRouteData { - static EnumParam _fromState(GoRouterState state) => EnumParam( - y: _$EnumTestEnumMap._$fromName(state.pathParameters['y']!)!, - ); + static EnumParam _fromState(GoRouterState state) => + EnumParam(y: _$EnumTestEnumMap._$fromName(state.pathParameters['y']!)!); EnumParam get _self => this as EnumParam; @override String get location => GoRouteData.$location( - '/${Uri.encodeComponent(_$EnumTestEnumMap[_self.y]!)}', - ); + '/${Uri.encodeComponent(_$EnumTestEnumMap[_self.y]!)}', + ); @override void go(BuildContext context) => context.go(location); @@ -29,11 +29,7 @@ mixin $EnumParam on GoRouteData { void replace(BuildContext context) => context.replace(location); } -const _$EnumTestEnumMap = { - EnumTest.a: 'a', - EnumTest.b: 'b', - EnumTest.c: 'c', -}; +const _$EnumTestEnumMap = {EnumTest.a: 'a', EnumTest.b: 'b', EnumTest.c: 'c'}; extension on Map { T? _$fromName(String? value) => diff --git a/packages/go_router_builder/test_inputs/extension_type_parameter.dart.expect b/packages/go_router_builder/test_inputs/extension_type_parameter.dart.expect index edacc303446a..d4f444c41368 100644 --- a/packages/go_router_builder/test_inputs/extension_type_parameter.dart.expect +++ b/packages/go_router_builder/test_inputs/extension_type_parameter.dart.expect @@ -1,62 +1,72 @@ RouteBase get $extensionTypeParam => GoRouteData.$route( - path: '/', - factory: $ExtensionTypeParam._fromState, - routes: [ - GoRouteData.$route( - path: 'string/:s', - factory: $ExtensionTypeStringParam._fromState, - ), - GoRouteData.$route( - path: 'string_default/:s', - factory: $ExtensionTypeStringDefaultParam._fromState, - ), - GoRouteData.$route( - path: 'int/:x', - factory: $ExtensionTypeIntParam._fromState, - ), - GoRouteData.$route( - path: 'int_default/:x', - factory: $ExtensionTypeIntDefaultParam._fromState, - ), - GoRouteData.$route( - path: 'double/:d', - factory: $ExtensionTypeDoubleParam._fromState, - ), - GoRouteData.$route( - path: 'num/:n', - factory: $ExtensionTypeNumParam._fromState, - ), - GoRouteData.$route( - path: 'bool/:b', - factory: $ExtensionTypeBoolParam._fromState, - ), - GoRouteData.$route( - path: 'enum/:value', - factory: $ExtensionTypeEnumType._fromState, - ), - GoRouteData.$route( - path: 'bigint/:bi', - factory: $ExtensionTypeBigIntParam._fromState, - ), - GoRouteData.$route( - path: 'datetime/:dt', - factory: $ExtensionTypeDateTimeParam._fromState, - ), - GoRouteData.$route( - path: 'uri/:uri', - factory: $ExtensionTypeUriType._fromState, - ), - ], - ); + path: '/', + hasOverriddenOnExit: false, + factory: $ExtensionTypeParam._fromState, + routes: [ + GoRouteData.$route( + path: 'string/:s', + hasOverriddenOnExit: false, + factory: $ExtensionTypeStringParam._fromState, + ), + GoRouteData.$route( + path: 'string_default/:s', + hasOverriddenOnExit: false, + factory: $ExtensionTypeStringDefaultParam._fromState, + ), + GoRouteData.$route( + path: 'int/:x', + hasOverriddenOnExit: false, + factory: $ExtensionTypeIntParam._fromState, + ), + GoRouteData.$route( + path: 'int_default/:x', + hasOverriddenOnExit: false, + factory: $ExtensionTypeIntDefaultParam._fromState, + ), + GoRouteData.$route( + path: 'double/:d', + hasOverriddenOnExit: false, + factory: $ExtensionTypeDoubleParam._fromState, + ), + GoRouteData.$route( + path: 'num/:n', + hasOverriddenOnExit: false, + factory: $ExtensionTypeNumParam._fromState, + ), + GoRouteData.$route( + path: 'bool/:b', + hasOverriddenOnExit: false, + factory: $ExtensionTypeBoolParam._fromState, + ), + GoRouteData.$route( + path: 'enum/:value', + hasOverriddenOnExit: false, + factory: $ExtensionTypeEnumType._fromState, + ), + GoRouteData.$route( + path: 'bigint/:bi', + hasOverriddenOnExit: false, + factory: $ExtensionTypeBigIntParam._fromState, + ), + GoRouteData.$route( + path: 'datetime/:dt', + hasOverriddenOnExit: false, + factory: $ExtensionTypeDateTimeParam._fromState, + ), + GoRouteData.$route( + path: 'uri/:uri', + hasOverriddenOnExit: false, + factory: $ExtensionTypeUriType._fromState, + ), + ], +); mixin $ExtensionTypeParam on GoRouteData { static ExtensionTypeParam _fromState(GoRouterState state) => ExtensionTypeParam(); @override - String get location => GoRouteData.$location( - '/', - ); + String get location => GoRouteData.$location('/'); @override void go(BuildContext context) => context.go(location); @@ -78,28 +88,28 @@ mixin $ExtensionTypeStringParam on GoRouteData { s: state.pathParameters['s']! as StringExtensionType, requiredValue: state.uri.queryParameters['required-value']! as StringExtensionType, - optionalNullableValue: state.uri - .queryParameters['optional-nullable-value'] as StringExtensionType?, + optionalNullableValue: + state.uri.queryParameters['optional-nullable-value'] + as StringExtensionType?, optionalDefaultValue: state.uri.queryParameters['optional-default-value'] - as StringExtensionType? ?? - const StringExtensionType('default'), + as StringExtensionType? ?? + const StringExtensionType('default'), ); ExtensionTypeStringParam get _self => this as ExtensionTypeStringParam; @override String get location => GoRouteData.$location( - '/string/${Uri.encodeComponent(_self.s as String)}', - queryParams: { - 'required-value': _self.requiredValue as String, - if (_self.optionalNullableValue != null) - 'optional-nullable-value': _self.optionalNullableValue! as String, - if (_self.optionalDefaultValue != - const StringExtensionType('default')) - 'optional-default-value': _self.optionalDefaultValue as String, - }, - ); + '/string/${Uri.encodeComponent(_self.s as String)}', + queryParams: { + 'required-value': _self.requiredValue as String, + if (_self.optionalNullableValue != null) + 'optional-nullable-value': _self.optionalNullableValue! as String, + if (_self.optionalDefaultValue != const StringExtensionType('default')) + 'optional-default-value': _self.optionalDefaultValue as String, + }, + ); @override void go(BuildContext context) => context.go(location); @@ -118,7 +128,8 @@ mixin $ExtensionTypeStringParam on GoRouteData { mixin $ExtensionTypeStringDefaultParam on GoRouteData { static ExtensionTypeStringDefaultParam _fromState(GoRouterState state) => ExtensionTypeStringDefaultParam( - s: state.pathParameters['s'] as StringExtensionType? ?? + s: + state.pathParameters['s'] as StringExtensionType? ?? const StringExtensionType('default'), ); @@ -127,8 +138,8 @@ mixin $ExtensionTypeStringDefaultParam on GoRouteData { @override String get location => GoRouteData.$location( - '/string_default/${Uri.encodeComponent(_self.s as String)}', - ); + '/string_default/${Uri.encodeComponent(_self.s as String)}', + ); @override void go(BuildContext context) => context.go(location); @@ -145,33 +156,35 @@ mixin $ExtensionTypeStringDefaultParam on GoRouteData { } mixin $ExtensionTypeIntParam on GoRouteData { - static ExtensionTypeIntParam _fromState(GoRouterState state) => - ExtensionTypeIntParam( - x: int.parse(state.pathParameters['x']!) as IntExtensionType, - requiredValue: int.parse(state.uri.queryParameters['required-value']!) + static ExtensionTypeIntParam _fromState( + GoRouterState state, + ) => ExtensionTypeIntParam( + x: int.parse(state.pathParameters['x']!) as IntExtensionType, + requiredValue: + int.parse(state.uri.queryParameters['required-value']!) as IntExtensionType, - optionalNullableValue: int.tryParse( - state.uri.queryParameters['optional-nullable-value'] ?? '') + optionalNullableValue: + int.tryParse(state.uri.queryParameters['optional-nullable-value'] ?? '') as IntExtensionType?, - optionalDefaultValue: int.tryParse( - state.uri.queryParameters['optional-default-value'] ?? '') - as IntExtensionType? ?? - const IntExtensionType(42), - ); + optionalDefaultValue: + int.tryParse(state.uri.queryParameters['optional-default-value'] ?? '') + as IntExtensionType? ?? + const IntExtensionType(42), + ); ExtensionTypeIntParam get _self => this as ExtensionTypeIntParam; @override String get location => GoRouteData.$location( - '/int/${Uri.encodeComponent(_self.x.toString())}', - queryParams: { - 'required-value': _self.requiredValue.toString(), - if (_self.optionalNullableValue != null) - 'optional-nullable-value': _self.optionalNullableValue!.toString(), - if (_self.optionalDefaultValue != const IntExtensionType(42)) - 'optional-default-value': _self.optionalDefaultValue.toString(), - }, - ); + '/int/${Uri.encodeComponent(_self.x.toString())}', + queryParams: { + 'required-value': _self.requiredValue.toString(), + if (_self.optionalNullableValue != null) + 'optional-nullable-value': _self.optionalNullableValue!.toString(), + if (_self.optionalDefaultValue != const IntExtensionType(42)) + 'optional-default-value': _self.optionalDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -190,7 +203,9 @@ mixin $ExtensionTypeIntParam on GoRouteData { mixin $ExtensionTypeIntDefaultParam on GoRouteData { static ExtensionTypeIntDefaultParam _fromState(GoRouterState state) => ExtensionTypeIntDefaultParam( - x: int.tryParse(state.pathParameters['x'] ?? '') as IntExtensionType? ?? + x: + int.tryParse(state.pathParameters['x'] ?? '') + as IntExtensionType? ?? const IntExtensionType(42), ); @@ -199,8 +214,8 @@ mixin $ExtensionTypeIntDefaultParam on GoRouteData { @override String get location => GoRouteData.$location( - '/int_default/${Uri.encodeComponent(_self.x.toString())}', - ); + '/int_default/${Uri.encodeComponent(_self.x.toString())}', + ); @override void go(BuildContext context) => context.go(location); @@ -223,11 +238,15 @@ mixin $ExtensionTypeDoubleParam on GoRouteData { requiredValue: double.parse(state.uri.queryParameters['required-value']!) as DoubleExtensionType, - optionalNullableValue: double.tryParse( - state.uri.queryParameters['optional-nullable-value'] ?? '') - as DoubleExtensionType?, - optionalDefaultValue: double.tryParse( - state.uri.queryParameters['optional-default-value'] ?? '') + optionalNullableValue: + double.tryParse( + state.uri.queryParameters['optional-nullable-value'] ?? '', + ) + as DoubleExtensionType?, + optionalDefaultValue: + double.tryParse( + state.uri.queryParameters['optional-default-value'] ?? '', + ) as DoubleExtensionType? ?? const DoubleExtensionType(3.14), ); @@ -236,15 +255,15 @@ mixin $ExtensionTypeDoubleParam on GoRouteData { @override String get location => GoRouteData.$location( - '/double/${Uri.encodeComponent(_self.d.toString())}', - queryParams: { - 'required-value': _self.requiredValue.toString(), - if (_self.optionalNullableValue != null) - 'optional-nullable-value': _self.optionalNullableValue!.toString(), - if (_self.optionalDefaultValue != const DoubleExtensionType(3.14)) - 'optional-default-value': _self.optionalDefaultValue.toString(), - }, - ); + '/double/${Uri.encodeComponent(_self.d.toString())}', + queryParams: { + 'required-value': _self.requiredValue.toString(), + if (_self.optionalNullableValue != null) + 'optional-nullable-value': _self.optionalNullableValue!.toString(), + if (_self.optionalDefaultValue != const DoubleExtensionType(3.14)) + 'optional-default-value': _self.optionalDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -261,33 +280,35 @@ mixin $ExtensionTypeDoubleParam on GoRouteData { } mixin $ExtensionTypeNumParam on GoRouteData { - static ExtensionTypeNumParam _fromState(GoRouterState state) => - ExtensionTypeNumParam( - n: num.parse(state.pathParameters['n']!) as NumExtensionType, - requiredValue: num.parse(state.uri.queryParameters['required-value']!) + static ExtensionTypeNumParam _fromState( + GoRouterState state, + ) => ExtensionTypeNumParam( + n: num.parse(state.pathParameters['n']!) as NumExtensionType, + requiredValue: + num.parse(state.uri.queryParameters['required-value']!) as NumExtensionType, - optionalNullableValue: num.tryParse( - state.uri.queryParameters['optional-nullable-value'] ?? '') + optionalNullableValue: + num.tryParse(state.uri.queryParameters['optional-nullable-value'] ?? '') as NumExtensionType?, - optionalDefaultValue: num.tryParse( - state.uri.queryParameters['optional-default-value'] ?? '') - as NumExtensionType? ?? - const NumExtensionType(3.14), - ); + optionalDefaultValue: + num.tryParse(state.uri.queryParameters['optional-default-value'] ?? '') + as NumExtensionType? ?? + const NumExtensionType(3.14), + ); ExtensionTypeNumParam get _self => this as ExtensionTypeNumParam; @override String get location => GoRouteData.$location( - '/num/${Uri.encodeComponent(_self.n.toString())}', - queryParams: { - 'required-value': _self.requiredValue.toString(), - if (_self.optionalNullableValue != null) - 'optional-nullable-value': _self.optionalNullableValue!.toString(), - if (_self.optionalDefaultValue != const NumExtensionType(3.14)) - 'optional-default-value': _self.optionalDefaultValue.toString(), - }, - ); + '/num/${Uri.encodeComponent(_self.n.toString())}', + queryParams: { + 'required-value': _self.requiredValue.toString(), + if (_self.optionalNullableValue != null) + 'optional-nullable-value': _self.optionalNullableValue!.toString(), + if (_self.optionalDefaultValue != const NumExtensionType(3.14)) + 'optional-default-value': _self.optionalDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -307,13 +328,18 @@ mixin $ExtensionTypeBoolParam on GoRouteData { static ExtensionTypeBoolParam _fromState(GoRouterState state) => ExtensionTypeBoolParam( b: bool.parse(state.pathParameters['b']!) as BoolExtensionType, - requiredValue: bool.parse(state.uri.queryParameters['required-value']!) - as BoolExtensionType, - optionalNullableValue: bool.tryParse( - state.uri.queryParameters['optional-nullable-value'] ?? '') - as BoolExtensionType?, - optionalDefaultValue: bool.tryParse( - state.uri.queryParameters['optional-default-value'] ?? '') + requiredValue: + bool.parse(state.uri.queryParameters['required-value']!) + as BoolExtensionType, + optionalNullableValue: + bool.tryParse( + state.uri.queryParameters['optional-nullable-value'] ?? '', + ) + as BoolExtensionType?, + optionalDefaultValue: + bool.tryParse( + state.uri.queryParameters['optional-default-value'] ?? '', + ) as BoolExtensionType? ?? const BoolExtensionType(true), ); @@ -322,15 +348,15 @@ mixin $ExtensionTypeBoolParam on GoRouteData { @override String get location => GoRouteData.$location( - '/bool/${Uri.encodeComponent(_self.b.toString())}', - queryParams: { - 'required-value': _self.requiredValue.toString(), - if (_self.optionalNullableValue != null) - 'optional-nullable-value': _self.optionalNullableValue!.toString(), - if (_self.optionalDefaultValue != const BoolExtensionType(true)) - 'optional-default-value': _self.optionalDefaultValue.toString(), - }, - ); + '/bool/${Uri.encodeComponent(_self.b.toString())}', + queryParams: { + 'required-value': _self.requiredValue.toString(), + if (_self.optionalNullableValue != null) + 'optional-nullable-value': _self.optionalNullableValue!.toString(), + if (_self.optionalDefaultValue != const BoolExtensionType(true)) + 'optional-default-value': _self.optionalDefaultValue.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -349,15 +375,23 @@ mixin $ExtensionTypeBoolParam on GoRouteData { mixin $ExtensionTypeEnumType on GoRouteData { static ExtensionTypeEnumType _fromState(GoRouterState state) => ExtensionTypeEnumType( - value: _$MyEnumEnumMap._$fromName(state.pathParameters['value']!) - as EnumExtensionType, - requiredValue: _$MyEnumEnumMap._$fromName( - state.uri.queryParameters['required-value']!) as EnumExtensionType, - optionalNullableValue: _$MyEnumEnumMap._$fromName( - state.uri.queryParameters['optional-nullable-value']) - as EnumExtensionType?, - optionalDefaultValue: _$MyEnumEnumMap._$fromName( - state.uri.queryParameters['optional-default-value']) + value: + _$MyEnumEnumMap._$fromName(state.pathParameters['value']!) + as EnumExtensionType, + requiredValue: + _$MyEnumEnumMap._$fromName( + state.uri.queryParameters['required-value']!, + ) + as EnumExtensionType, + optionalNullableValue: + _$MyEnumEnumMap._$fromName( + state.uri.queryParameters['optional-nullable-value'], + ) + as EnumExtensionType?, + optionalDefaultValue: + _$MyEnumEnumMap._$fromName( + state.uri.queryParameters['optional-default-value'], + ) as EnumExtensionType? ?? const EnumExtensionType(MyEnum.value1), ); @@ -366,18 +400,17 @@ mixin $ExtensionTypeEnumType on GoRouteData { @override String get location => GoRouteData.$location( - '/enum/${Uri.encodeComponent(_$MyEnumEnumMap[_self.value as MyEnum]!)}', - queryParams: { - 'required-value': _$MyEnumEnumMap[_self.requiredValue as MyEnum]!, - if (_self.optionalNullableValue != null) - 'optional-nullable-value': - _$MyEnumEnumMap[_self.optionalNullableValue! as MyEnum]!, - if (_self.optionalDefaultValue != - const EnumExtensionType(MyEnum.value1)) - 'optional-default-value': - _$MyEnumEnumMap[_self.optionalDefaultValue as MyEnum]!, - }, - ); + '/enum/${Uri.encodeComponent(_$MyEnumEnumMap[_self.value as MyEnum]!)}', + queryParams: { + 'required-value': _$MyEnumEnumMap[_self.requiredValue as MyEnum]!, + if (_self.optionalNullableValue != null) + 'optional-nullable-value': + _$MyEnumEnumMap[_self.optionalNullableValue! as MyEnum]!, + if (_self.optionalDefaultValue != const EnumExtensionType(MyEnum.value1)) + 'optional-default-value': + _$MyEnumEnumMap[_self.optionalDefaultValue as MyEnum]!, + }, + ); @override void go(BuildContext context) => context.go(location); @@ -409,24 +442,26 @@ mixin $ExtensionTypeBigIntParam on GoRouteData { optionalValue: BigInt.tryParse(state.uri.queryParameters['optional-value'] ?? '') as BigIntExtensionType?, - optionalNullableValue: BigInt.tryParse( - state.uri.queryParameters['optional-nullable-value'] ?? '') - as BigIntExtensionType?, + optionalNullableValue: + BigInt.tryParse( + state.uri.queryParameters['optional-nullable-value'] ?? '', + ) + as BigIntExtensionType?, ); ExtensionTypeBigIntParam get _self => this as ExtensionTypeBigIntParam; @override String get location => GoRouteData.$location( - '/bigint/${Uri.encodeComponent(_self.bi.toString())}', - queryParams: { - 'required-value': _self.requiredValue.toString(), - if (_self.optionalValue != null) - 'optional-value': _self.optionalValue!.toString(), - if (_self.optionalNullableValue != null) - 'optional-nullable-value': _self.optionalNullableValue!.toString(), - }, - ); + '/bigint/${Uri.encodeComponent(_self.bi.toString())}', + queryParams: { + 'required-value': _self.requiredValue.toString(), + if (_self.optionalValue != null) + 'optional-value': _self.optionalValue!.toString(), + if (_self.optionalNullableValue != null) + 'optional-nullable-value': _self.optionalNullableValue!.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -443,29 +478,31 @@ mixin $ExtensionTypeBigIntParam on GoRouteData { } mixin $ExtensionTypeDateTimeParam on GoRouteData { - static ExtensionTypeDateTimeParam _fromState(GoRouterState state) => - ExtensionTypeDateTimeParam( - dt: DateTime.parse(state.pathParameters['dt']!) + static ExtensionTypeDateTimeParam _fromState( + GoRouterState state, + ) => ExtensionTypeDateTimeParam( + dt: DateTime.parse(state.pathParameters['dt']!) as DateTimeExtensionType, + optionalValue: + DateTime.parse(state.uri.queryParameters['optional-value']!) as DateTimeExtensionType, - optionalValue: - DateTime.parse(state.uri.queryParameters['optional-value']!) - as DateTimeExtensionType, - optionalNullableValue: DateTime.tryParse( - state.uri.queryParameters['optional-nullable-value'] ?? '') + optionalNullableValue: + DateTime.tryParse( + state.uri.queryParameters['optional-nullable-value'] ?? '', + ) as DateTimeExtensionType?, - ); + ); ExtensionTypeDateTimeParam get _self => this as ExtensionTypeDateTimeParam; @override String get location => GoRouteData.$location( - '/datetime/${Uri.encodeComponent(_self.dt.toString())}', - queryParams: { - 'optional-value': _self.optionalValue.toString(), - if (_self.optionalNullableValue != null) - 'optional-nullable-value': _self.optionalNullableValue!.toString(), - }, - ); + '/datetime/${Uri.encodeComponent(_self.dt.toString())}', + queryParams: { + 'optional-value': _self.optionalValue.toString(), + if (_self.optionalNullableValue != null) + 'optional-nullable-value': _self.optionalNullableValue!.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); @@ -485,24 +522,27 @@ mixin $ExtensionTypeUriType on GoRouteData { static ExtensionTypeUriType _fromState(GoRouterState state) => ExtensionTypeUriType( uri: Uri.parse(state.pathParameters['uri']!) as UriExtensionType, - requiredValue: Uri.parse(state.uri.queryParameters['required-value']!) - as UriExtensionType, - optionalNullableValue: Uri.tryParse( - state.uri.queryParameters['optional-nullable-value'] ?? '') - as UriExtensionType?, + requiredValue: + Uri.parse(state.uri.queryParameters['required-value']!) + as UriExtensionType, + optionalNullableValue: + Uri.tryParse( + state.uri.queryParameters['optional-nullable-value'] ?? '', + ) + as UriExtensionType?, ); ExtensionTypeUriType get _self => this as ExtensionTypeUriType; @override String get location => GoRouteData.$location( - '/uri/${Uri.encodeComponent(_self.uri.toString())}', - queryParams: { - 'required-value': _self.requiredValue.toString(), - if (_self.optionalNullableValue != null) - 'optional-nullable-value': _self.optionalNullableValue!.toString(), - }, - ); + '/uri/${Uri.encodeComponent(_self.uri.toString())}', + queryParams: { + 'required-value': _self.requiredValue.toString(), + if (_self.optionalNullableValue != null) + 'optional-nullable-value': _self.optionalNullableValue!.toString(), + }, + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/extra_value.dart.expect b/packages/go_router_builder/test_inputs/extra_value.dart.expect index bc2ef59b43c1..a4777ae24f9d 100644 --- a/packages/go_router_builder/test_inputs/extra_value.dart.expect +++ b/packages/go_router_builder/test_inputs/extra_value.dart.expect @@ -1,25 +1,23 @@ RouteBase get $extraValueRoute => GoRouteData.$route( - path: '/default-value-route', - factory: $ExtraValueRoute._fromState, - ); + path: '/default-value-route', + hasOverriddenOnExit: false, + factory: $ExtraValueRoute._fromState, +); mixin $ExtraValueRoute on GoRouteData { static ExtraValueRoute _fromState(GoRouterState state) => ExtraValueRoute( - param: - _$convertMapValue('param', state.uri.queryParameters, int.parse) ?? - 0, - $extra: state.extra as int?, - ); + param: + _$convertMapValue('param', state.uri.queryParameters, int.parse) ?? 0, + $extra: state.extra as int?, + ); ExtraValueRoute get _self => this as ExtraValueRoute; @override String get location => GoRouteData.$location( - '/default-value-route', - queryParams: { - if (_self.param != 0) 'param': _self.param.toString(), - }, - ); + '/default-value-route', + queryParams: {if (_self.param != 0) 'param': _self.param.toString()}, + ); @override void go(BuildContext context) => context.go(location, extra: _self.$extra); diff --git a/packages/go_router_builder/test_inputs/go_relative.dart.expect b/packages/go_router_builder/test_inputs/go_relative.dart.expect index 6996962c3e66..2bf74fd08c3f 100644 --- a/packages/go_router_builder/test_inputs/go_relative.dart.expect +++ b/packages/go_router_builder/test_inputs/go_relative.dart.expect @@ -1,27 +1,28 @@ RouteBase get $route1 => GoRouteData.$route( - path: 'route-1', - factory: $Route1._fromState, + path: 'route-1', + hasOverriddenOnExit: false, + factory: $Route1._fromState, + routes: [ + RelativeGoRouteData.$route( + path: 'relative-route', + hasOverriddenOnExit: false, + factory: $RelativeRoute._fromState, routes: [ RelativeGoRouteData.$route( - path: 'relative-route', - factory: $RelativeRoute._fromState, - routes: [ - RelativeGoRouteData.$route( - path: 'inner-relative-route', - factory: $InnerRelativeRoute._fromState, - ), - ], + path: 'inner-relative-route', + hasOverriddenOnExit: false, + factory: $InnerRelativeRoute._fromState, ), ], - ); + ), + ], +); mixin $Route1 on GoRouteData { static Route1 _fromState(GoRouterState state) => const Route1(); @override - String get location => GoRouteData.$location( - 'route-1', - ); + String get location => GoRouteData.$location('route-1'); @override void go(BuildContext context) => context.go(location); @@ -41,9 +42,7 @@ mixin $RelativeRoute on RelativeGoRouteData { static RelativeRoute _fromState(GoRouterState state) => const RelativeRoute(); @override - String get subLocation => RelativeGoRouteData.$location( - 'relative-route', - ); + String get subLocation => RelativeGoRouteData.$location('relative-route'); @override String get relativeLocation => './$subLocation'; @@ -69,9 +68,8 @@ mixin $InnerRelativeRoute on RelativeGoRouteData { const InnerRelativeRoute(); @override - String get subLocation => RelativeGoRouteData.$location( - 'inner-relative-route', - ); + String get subLocation => + RelativeGoRouteData.$location('inner-relative-route'); @override String get relativeLocation => './$subLocation'; @@ -93,29 +91,30 @@ mixin $InnerRelativeRoute on RelativeGoRouteData { } RouteBase get $route2 => GoRouteData.$route( - path: 'route-2', - factory: $Route2._fromState, + path: 'route-2', + hasOverriddenOnExit: false, + factory: $Route2._fromState, + routes: [ + RelativeGoRouteData.$route( + path: 'relative-route', + hasOverriddenOnExit: false, + factory: $RelativeRoute._fromState, routes: [ RelativeGoRouteData.$route( - path: 'relative-route', - factory: $RelativeRoute._fromState, - routes: [ - RelativeGoRouteData.$route( - path: 'inner-relative-route', - factory: $InnerRelativeRoute._fromState, - ), - ], + path: 'inner-relative-route', + hasOverriddenOnExit: false, + factory: $InnerRelativeRoute._fromState, ), ], - ); + ), + ], +); mixin $Route2 on GoRouteData { static Route2 _fromState(GoRouterState state) => const Route2(); @override - String get location => GoRouteData.$location( - 'route-2', - ); + String get location => GoRouteData.$location('route-2'); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/iterable_with_default_value.dart.expect b/packages/go_router_builder/test_inputs/iterable_with_default_value.dart.expect index 45c3631c9af1..2489b61021f6 100644 --- a/packages/go_router_builder/test_inputs/iterable_with_default_value.dart.expect +++ b/packages/go_router_builder/test_inputs/iterable_with_default_value.dart.expect @@ -1,26 +1,27 @@ RouteBase get $iterableDefaultValueRoute => GoRouteData.$route( - path: '/iterable-default-value-route', - factory: $IterableDefaultValueRoute._fromState, - ); + path: '/iterable-default-value-route', + hasOverriddenOnExit: false, + factory: $IterableDefaultValueRoute._fromState, +); mixin $IterableDefaultValueRoute on GoRouteData { static IterableDefaultValueRoute _fromState(GoRouterState state) => IterableDefaultValueRoute( param: state.uri.queryParametersAll['param']?.map(int.parse).cast() ?? - const [0], + const [0], ); IterableDefaultValueRoute get _self => this as IterableDefaultValueRoute; @override String get location => GoRouteData.$location( - '/iterable-default-value-route', - queryParams: { - if (!_$iterablesEqual(_self.param, const [0])) - 'param': _self.param.map((e) => e.toString()).toList(), - }, - ); + '/iterable-default-value-route', + queryParams: { + if (!_$iterablesEqual(_self.param, const [0])) + 'param': _self.param.map((e) => e.toString()).toList(), + }, + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/iterable_with_enum.dart.expect b/packages/go_router_builder/test_inputs/iterable_with_enum.dart.expect index 5dbdac5865b6..2ee8662f08f7 100644 --- a/packages/go_router_builder/test_inputs/iterable_with_enum.dart.expect +++ b/packages/go_router_builder/test_inputs/iterable_with_enum.dart.expect @@ -1,7 +1,8 @@ RouteBase get $iterableWithEnumRoute => GoRouteData.$route( - path: '/iterable-with-enum', - factory: $IterableWithEnumRoute._fromState, - ); + path: '/iterable-with-enum', + hasOverriddenOnExit: false, + factory: $IterableWithEnumRoute._fromState, +); mixin $IterableWithEnumRoute on GoRouteData { static IterableWithEnumRoute _fromState(GoRouterState state) => @@ -15,14 +16,14 @@ mixin $IterableWithEnumRoute on GoRouteData { @override String get location => GoRouteData.$location( - '/iterable-with-enum', - queryParams: { - if (_self.param != null) - 'param': _self.param - ?.map((e) => _$EnumOnlyUsedInIterableEnumMap[e]) - .toList(), - }, - ); + '/iterable-with-enum', + queryParams: { + if (_self.param != null) + 'param': _self.param + ?.map((e) => _$EnumOnlyUsedInIterableEnumMap[e]) + .toList(), + }, + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/json.dart.expect b/packages/go_router_builder/test_inputs/json.dart.expect index 56e0bf4814a4..ab20a0905435 100644 --- a/packages/go_router_builder/test_inputs/json.dart.expect +++ b/packages/go_router_builder/test_inputs/json.dart.expect @@ -1,5 +1,8 @@ -RouteBase get $goodJson => - GoRouteData.$route(path: '/', factory: $GoodJson._fromState); +RouteBase get $goodJson => GoRouteData.$route( + path: '/', + hasOverriddenOnExit: false, + factory: $GoodJson._fromState, +); mixin $GoodJson on GoRouteData { static GoodJson _fromState(GoRouterState state) => GoodJson( diff --git a/packages/go_router_builder/test_inputs/json_template.dart.expect b/packages/go_router_builder/test_inputs/json_template.dart.expect index a2c04c4392ba..ab7d7ddf4d32 100644 --- a/packages/go_router_builder/test_inputs/json_template.dart.expect +++ b/packages/go_router_builder/test_inputs/json_template.dart.expect @@ -1,45 +1,46 @@ RouteBase get $jsonTemplateRoute => GoRouteData.$route( - path: '/', - factory: $JsonTemplateRoute._fromState, - ); + path: '/', + hasOverriddenOnExit: false, + factory: $JsonTemplateRoute._fromState, +); mixin $JsonTemplateRoute on GoRouteData { static JsonTemplateRoute _fromState(GoRouterState state) => JsonTemplateRoute( - nested: (String json0) { - return JsonExampleNested.fromJson( - jsonDecode(json0) as Map, - (Object? json1) { - return JsonExample.fromJson(json1 as Map); - }, - ); - }(state.uri.queryParameters['nested']!), - deepNested: _$convertMapValue('deep-nested', state.uri.queryParameters, - (String json0) { - return JsonExampleNested.fromJson( - jsonDecode(json0) as Map, - (Object? json1) { - return JsonExampleNested.fromJson( - json1 as Map, - (Object? json2) { - return JsonExample.fromJson(json2 as Map); - }, - ); - }, - ); - }), + nested: (String json0) { + return JsonExampleNested.fromJson( + jsonDecode(json0) as Map, + (Object? json1) { + return JsonExample.fromJson(json1 as Map); + }, + ); + }(state.uri.queryParameters['nested']!), + deepNested: _$convertMapValue('deep-nested', state.uri.queryParameters, ( + String json0, + ) { + return JsonExampleNested.fromJson( + jsonDecode(json0) as Map, + (Object? json1) { + return JsonExampleNested.fromJson(json1 as Map, ( + Object? json2, + ) { + return JsonExample.fromJson(json2 as Map); + }); + }, ); + }), + ); JsonTemplateRoute get _self => this as JsonTemplateRoute; @override String get location => GoRouteData.$location( - '/', - queryParams: { - 'nested': jsonEncode(_self.nested.toJson()), - if (_self.deepNested != null) - 'deep-nested': jsonEncode(_self.deepNested!.toJson()), - }, - ); + '/', + queryParams: { + 'nested': jsonEncode(_self.nested.toJson()), + if (_self.deepNested != null) + 'deep-nested': jsonEncode(_self.deepNested!.toJson()), + }, + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/list.dart.expect b/packages/go_router_builder/test_inputs/list.dart.expect index 01748fc2728c..fab99a9a128f 100644 --- a/packages/go_router_builder/test_inputs/list.dart.expect +++ b/packages/go_router_builder/test_inputs/list.dart.expect @@ -1,42 +1,44 @@ RouteBase get $listRoute => GoRouteData.$route( - path: '/list-route', - factory: $ListRoute._fromState, - ); + path: '/list-route', + hasOverriddenOnExit: false, + factory: $ListRoute._fromState, +); mixin $ListRoute on GoRouteData { static ListRoute _fromState(GoRouterState state) => ListRoute( - ids: state.uri.queryParametersAll['ids'] - ?.map(int.parse) - .cast() - .toList() ?? - const [], - nullableIds: state.uri.queryParametersAll['nullable-ids'] + ids: + state.uri.queryParametersAll['ids'] ?.map(int.parse) .cast() - .toList(), - idsWithDefaultValue: state - .uri.queryParametersAll['ids-with-default-value'] - ?.map(int.parse) - .cast() - .toList() ?? - const [0], - ); + .toList() ?? + const [], + nullableIds: state.uri.queryParametersAll['nullable-ids'] + ?.map(int.parse) + .cast() + .toList(), + idsWithDefaultValue: + state.uri.queryParametersAll['ids-with-default-value'] + ?.map(int.parse) + .cast() + .toList() ?? + const [0], + ); ListRoute get _self => this as ListRoute; @override String get location => GoRouteData.$location( - '/list-route', - queryParams: { - 'ids': _self.ids.map((e) => e.toString()).toList(), - if (_self.nullableIds != null) - 'nullable-ids': - _self.nullableIds?.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(_self.idsWithDefaultValue, const [0])) - 'ids-with-default-value': - _self.idsWithDefaultValue.map((e) => e.toString()).toList(), - }, - ); + '/list-route', + queryParams: { + 'ids': _self.ids.map((e) => e.toString()).toList(), + if (_self.nullableIds != null) + 'nullable-ids': _self.nullableIds?.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.idsWithDefaultValue, const [0])) + 'ids-with-default-value': _self.idsWithDefaultValue + .map((e) => e.toString()) + .toList(), + }, + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/named_escaped_route.dart.expect b/packages/go_router_builder/test_inputs/named_escaped_route.dart.expect index a55b7e2e7202..6029a4b4f00d 100644 --- a/packages/go_router_builder/test_inputs/named_escaped_route.dart.expect +++ b/packages/go_router_builder/test_inputs/named_escaped_route.dart.expect @@ -1,17 +1,16 @@ RouteBase get $namedEscapedRoute => GoRouteData.$route( - path: '/named-route', - name: r'named$Route', - factory: $NamedEscapedRoute._fromState, - ); + path: '/named-route', + name: r'named$Route', + hasOverriddenOnExit: false, + factory: $NamedEscapedRoute._fromState, +); mixin $NamedEscapedRoute on GoRouteData { static NamedEscapedRoute _fromState(GoRouterState state) => NamedEscapedRoute(); @override - String get location => GoRouteData.$location( - '/named-route', - ); + String get location => GoRouteData.$location('/named-route'); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/named_route.dart.expect b/packages/go_router_builder/test_inputs/named_route.dart.expect index 51f04ba430a6..83b16d9ff14f 100644 --- a/packages/go_router_builder/test_inputs/named_route.dart.expect +++ b/packages/go_router_builder/test_inputs/named_route.dart.expect @@ -1,16 +1,15 @@ RouteBase get $namedRoute => GoRouteData.$route( - path: '/named-route', - name: 'namedRoute', - factory: $NamedRoute._fromState, - ); + path: '/named-route', + name: 'namedRoute', + hasOverriddenOnExit: false, + factory: $NamedRoute._fromState, +); mixin $NamedRoute on GoRouteData { static NamedRoute _fromState(GoRouterState state) => NamedRoute(); @override - String get location => GoRouteData.$location( - '/named-route', - ); + String get location => GoRouteData.$location('/named-route'); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/on_exit.dart b/packages/go_router_builder/test_inputs/on_exit.dart new file mode 100644 index 000000000000..e9a1a7ff9710 --- /dev/null +++ b/packages/go_router_builder/test_inputs/on_exit.dart @@ -0,0 +1,48 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:go_router/go_router.dart'; + +mixin $HomeRoute {} +mixin $ConfirmExitRoute {} +mixin $InheritedExitRoute {} +mixin $RelativeExitRoute {} + +@TypedGoRoute( + path: '/', + routes: >[ + TypedGoRoute(path: 'confirm-exit'), + TypedGoRoute(path: 'inherited-exit'), + TypedRelativeGoRoute(path: 'relative-exit'), + ], +) +class HomeRoute extends GoRouteData with $HomeRoute { + const HomeRoute(); +} + +class ConfirmExitRoute extends GoRouteData with $ConfirmExitRoute { + const ConfirmExitRoute(); + + @override + bool onExit(BuildContext context, GoRouterState state) => false; +} + +abstract class BaseExitRoute extends GoRouteData { + const BaseExitRoute(); + + @override + bool onExit(BuildContext context, GoRouterState state) => false; +} + +class InheritedExitRoute extends BaseExitRoute with $InheritedExitRoute { + const InheritedExitRoute(); +} + +class RelativeExitRoute extends RelativeGoRouteData with $RelativeExitRoute { + const RelativeExitRoute(); + + @override + bool onExit(BuildContext context, GoRouterState state) => false; +} diff --git a/packages/go_router_builder/test_inputs/on_exit.dart.expect b/packages/go_router_builder/test_inputs/on_exit.dart.expect new file mode 100644 index 000000000000..3e8e8d66777c --- /dev/null +++ b/packages/go_router_builder/test_inputs/on_exit.dart.expect @@ -0,0 +1,110 @@ +RouteBase get $homeRoute => GoRouteData.$route( + path: '/', + hasOverriddenOnExit: false, + factory: $HomeRoute._fromState, + routes: [ + GoRouteData.$route( + path: 'confirm-exit', + hasOverriddenOnExit: true, + factory: $ConfirmExitRoute._fromState, + ), + GoRouteData.$route( + path: 'inherited-exit', + hasOverriddenOnExit: true, + factory: $InheritedExitRoute._fromState, + ), + RelativeGoRouteData.$route( + path: 'relative-exit', + hasOverriddenOnExit: true, + factory: $RelativeExitRoute._fromState, + ), + ], +); + +mixin $HomeRoute on GoRouteData { + static HomeRoute _fromState(GoRouterState state) => const HomeRoute(); + + @override + String get location => GoRouteData.$location('/'); + + @override + void go(BuildContext context) => context.go(location); + + @override + Future push(BuildContext context) => context.push(location); + + @override + void pushReplacement(BuildContext context) => + context.pushReplacement(location); + + @override + void replace(BuildContext context) => context.replace(location); +} + +mixin $ConfirmExitRoute on GoRouteData { + static ConfirmExitRoute _fromState(GoRouterState state) => + const ConfirmExitRoute(); + + @override + String get location => GoRouteData.$location('/confirm-exit'); + + @override + void go(BuildContext context) => context.go(location); + + @override + Future push(BuildContext context) => context.push(location); + + @override + void pushReplacement(BuildContext context) => + context.pushReplacement(location); + + @override + void replace(BuildContext context) => context.replace(location); +} + +mixin $InheritedExitRoute on GoRouteData { + static InheritedExitRoute _fromState(GoRouterState state) => + const InheritedExitRoute(); + + @override + String get location => GoRouteData.$location('/inherited-exit'); + + @override + void go(BuildContext context) => context.go(location); + + @override + Future push(BuildContext context) => context.push(location); + + @override + void pushReplacement(BuildContext context) => + context.pushReplacement(location); + + @override + void replace(BuildContext context) => context.replace(location); +} + +mixin $RelativeExitRoute on RelativeGoRouteData { + static RelativeExitRoute _fromState(GoRouterState state) => + const RelativeExitRoute(); + + @override + String get subLocation => RelativeGoRouteData.$location('relative-exit'); + + @override + String get relativeLocation => './$subLocation'; + + @override + void goRelative(BuildContext context) => context.go(relativeLocation); + + @override + Future pushRelative(BuildContext context) => + context.push(relativeLocation); + + @override + void pushReplacementRelative(BuildContext context) => + context.pushReplacement(relativeLocation); + + @override + void replaceRelative(BuildContext context) => + context.replace(relativeLocation); +} diff --git a/packages/go_router_builder/test_inputs/parameter_generates_a_warning.dart.expect b/packages/go_router_builder/test_inputs/parameter_generates_a_warning.dart.expect index 0736d3534ddd..cf3b23114060 100644 --- a/packages/go_router_builder/test_inputs/parameter_generates_a_warning.dart.expect +++ b/packages/go_router_builder/test_inputs/parameter_generates_a_warning.dart.expect @@ -1,19 +1,19 @@ RouteBase get $myRoute => GoRouteData.$route( - path: '/product/:id', - factory: $MyRoute._fromState, - ); + path: '/product/:id', + hasOverriddenOnExit: false, + factory: $MyRoute._fromState, +); mixin $MyRoute on GoRouteData { - static MyRoute _fromState(GoRouterState state) => MyRoute( - int.parse(state.pathParameters['id']!), - ); + static MyRoute _fromState(GoRouterState state) => + MyRoute(int.parse(state.pathParameters['id']!)); MyRoute get _self => this as MyRoute; @override String get location => GoRouteData.$location( - '/product/${Uri.encodeComponent(_self.id.toString())}', - ); + '/product/${Uri.encodeComponent(_self.id.toString())}', + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/required_extra_value.dart.expect b/packages/go_router_builder/test_inputs/required_extra_value.dart.expect index 6dd659bee942..3021a7afa253 100644 --- a/packages/go_router_builder/test_inputs/required_extra_value.dart.expect +++ b/packages/go_router_builder/test_inputs/required_extra_value.dart.expect @@ -1,20 +1,17 @@ RouteBase get $requiredExtraValueRoute => GoRouteData.$route( - path: '/default-value-route', - factory: $RequiredExtraValueRoute._fromState, - ); + path: '/default-value-route', + hasOverriddenOnExit: false, + factory: $RequiredExtraValueRoute._fromState, +); mixin $RequiredExtraValueRoute on GoRouteData { static RequiredExtraValueRoute _fromState(GoRouterState state) => - RequiredExtraValueRoute( - $extra: state.extra as int, - ); + RequiredExtraValueRoute($extra: state.extra as int); RequiredExtraValueRoute get _self => this as RequiredExtraValueRoute; @override - String get location => GoRouteData.$location( - '/default-value-route', - ); + String get location => GoRouteData.$location('/default-value-route'); @override void go(BuildContext context) => context.go(location, extra: _self.$extra); diff --git a/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect index d61f172f79ac..0548fc88a7c1 100644 --- a/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect +++ b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect @@ -1,23 +1,22 @@ RouteBase get $requiredNullableTypeArgumentsExtraValueRoute => GoRouteData.$route( path: '/default-value-route', + hasOverriddenOnExit: false, factory: $RequiredNullableTypeArgumentsExtraValueRoute._fromState, ); mixin $RequiredNullableTypeArgumentsExtraValueRoute on GoRouteData { static RequiredNullableTypeArgumentsExtraValueRoute _fromState( - GoRouterState state) => - RequiredNullableTypeArgumentsExtraValueRoute( - $extra: state.extra as List, - ); + GoRouterState state, + ) => RequiredNullableTypeArgumentsExtraValueRoute( + $extra: state.extra as List, + ); RequiredNullableTypeArgumentsExtraValueRoute get _self => this as RequiredNullableTypeArgumentsExtraValueRoute; @override - String get location => GoRouteData.$location( - '/default-value-route', - ); + String get location => GoRouteData.$location('/default-value-route'); @override void go(BuildContext context) => context.go(location, extra: _self.$extra); diff --git a/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart.expect b/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart.expect index 92ee37966bd7..fcf612b35e03 100644 --- a/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart.expect +++ b/packages/go_router_builder/test_inputs/required_parameters_not_in_path_can_be_null.dart.expect @@ -1,7 +1,8 @@ RouteBase get $nullableRequiredParamNotInPath => GoRouteData.$route( - path: 'bob', - factory: $NullableRequiredParamNotInPath._fromState, - ); + path: 'bob', + hasOverriddenOnExit: false, + factory: $NullableRequiredParamNotInPath._fromState, +); mixin $NullableRequiredParamNotInPath on GoRouteData { static NullableRequiredParamNotInPath _fromState(GoRouterState state) => @@ -14,11 +15,9 @@ mixin $NullableRequiredParamNotInPath on GoRouteData { @override String get location => GoRouteData.$location( - 'bob', - queryParams: { - if (_self.id != null) 'id': _self.id!.toString(), - }, - ); + 'bob', + queryParams: {if (_self.id != null) 'id': _self.id!.toString()}, + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/required_query_parameter.dart.expect b/packages/go_router_builder/test_inputs/required_query_parameter.dart.expect index 28c151377131..e9e3f1c20e5e 100644 --- a/packages/go_router_builder/test_inputs/required_query_parameter.dart.expect +++ b/packages/go_router_builder/test_inputs/required_query_parameter.dart.expect @@ -1,7 +1,8 @@ RouteBase get $nonNullableRequiredParamNotInPath => GoRouteData.$route( - path: 'bob', - factory: $NonNullableRequiredParamNotInPath._fromState, - ); + path: 'bob', + hasOverriddenOnExit: false, + factory: $NonNullableRequiredParamNotInPath._fromState, +); mixin $NonNullableRequiredParamNotInPath on GoRouteData { static NonNullableRequiredParamNotInPath _fromState(GoRouterState state) => @@ -13,12 +14,8 @@ mixin $NonNullableRequiredParamNotInPath on GoRouteData { this as NonNullableRequiredParamNotInPath; @override - String get location => GoRouteData.$location( - 'bob', - queryParams: { - 'id': _self.id.toString(), - }, - ); + String get location => + GoRouteData.$location('bob', queryParams: {'id': _self.id.toString()}); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/set.dart.expect b/packages/go_router_builder/test_inputs/set.dart.expect index 3fa675958fd3..504ad17b0974 100644 --- a/packages/go_router_builder/test_inputs/set.dart.expect +++ b/packages/go_router_builder/test_inputs/set.dart.expect @@ -1,42 +1,44 @@ RouteBase get $setRoute => GoRouteData.$route( - path: '/set-route', - factory: $SetRoute._fromState, - ); + path: '/set-route', + hasOverriddenOnExit: false, + factory: $SetRoute._fromState, +); mixin $SetRoute on GoRouteData { static SetRoute _fromState(GoRouterState state) => SetRoute( - ids: state.uri.queryParametersAll['ids'] - ?.map(int.parse) - .cast() - .toSet() ?? - const {}, - nullableIds: state.uri.queryParametersAll['nullable-ids'] + ids: + state.uri.queryParametersAll['ids'] ?.map(int.parse) .cast() - .toSet(), - idsWithDefaultValue: state - .uri.queryParametersAll['ids-with-default-value'] - ?.map(int.parse) - .cast() - .toSet() ?? - const {0}, - ); + .toSet() ?? + const {}, + nullableIds: state.uri.queryParametersAll['nullable-ids'] + ?.map(int.parse) + .cast() + .toSet(), + idsWithDefaultValue: + state.uri.queryParametersAll['ids-with-default-value'] + ?.map(int.parse) + .cast() + .toSet() ?? + const {0}, + ); SetRoute get _self => this as SetRoute; @override String get location => GoRouteData.$location( - '/set-route', - queryParams: { - 'ids': _self.ids.map((e) => e.toString()).toList(), - if (_self.nullableIds != null) - 'nullable-ids': - _self.nullableIds?.map((e) => e.toString()).toList(), - if (!_$iterablesEqual(_self.idsWithDefaultValue, const {0})) - 'ids-with-default-value': - _self.idsWithDefaultValue.map((e) => e.toString()).toList(), - }, - ); + '/set-route', + queryParams: { + 'ids': _self.ids.map((e) => e.toString()).toList(), + if (_self.nullableIds != null) + 'nullable-ids': _self.nullableIds?.map((e) => e.toString()).toList(), + if (!_$iterablesEqual(_self.idsWithDefaultValue, const {0})) + 'ids-with-default-value': _self.idsWithDefaultValue + .map((e) => e.toString()) + .toList(), + }, + ); @override void go(BuildContext context) => context.go(location); diff --git a/packages/go_router_builder/test_inputs/shell_route_data.dart.expect b/packages/go_router_builder/test_inputs/shell_route_data.dart.expect index 106211100ed8..292908c8f164 100644 --- a/packages/go_router_builder/test_inputs/shell_route_data.dart.expect +++ b/packages/go_router_builder/test_inputs/shell_route_data.dart.expect @@ -1,6 +1,6 @@ RouteBase get $shellRouteNoConstConstructor => ShellRouteData.$route( - factory: $ShellRouteNoConstConstructorExtension._fromState, - ); + factory: $ShellRouteNoConstConstructorExtension._fromState, +); extension $ShellRouteNoConstConstructorExtension on ShellRouteNoConstConstructor { @@ -9,8 +9,8 @@ extension $ShellRouteNoConstConstructorExtension } RouteBase get $shellRouteWithConstConstructor => ShellRouteData.$route( - factory: $ShellRouteWithConstConstructorExtension._fromState, - ); + factory: $ShellRouteWithConstConstructorExtension._fromState, +); extension $ShellRouteWithConstConstructorExtension on ShellRouteWithConstConstructor { @@ -19,9 +19,9 @@ extension $ShellRouteWithConstConstructorExtension } RouteBase get $shellRouteWithRestorationScopeId => ShellRouteData.$route( - restorationScopeId: ShellRouteWithRestorationScopeId.$restorationScopeId, - factory: $ShellRouteWithRestorationScopeIdExtension._fromState, - ); + restorationScopeId: ShellRouteWithRestorationScopeId.$restorationScopeId, + factory: $ShellRouteWithRestorationScopeIdExtension._fromState, +); extension $ShellRouteWithRestorationScopeIdExtension on ShellRouteWithRestorationScopeId { diff --git a/packages/go_router_builder/test_inputs/stateful_shell_branch_data.dart.expect b/packages/go_router_builder/test_inputs/stateful_shell_branch_data.dart.expect index 07b95b1deeb8..17664e676ed1 100644 --- a/packages/go_router_builder/test_inputs/stateful_shell_branch_data.dart.expect +++ b/packages/go_router_builder/test_inputs/stateful_shell_branch_data.dart.expect @@ -1,3 +1,3 @@ RouteBase get $shellRouteBranchData => StatefulShellBranchData.$branch( - initialLocation: ShellRouteBranchData.$initialLocation, - ); + initialLocation: ShellRouteBranchData.$initialLocation, +); diff --git a/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart.expect b/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart.expect index df121eb6f0f4..5b799a77bdaa 100644 --- a/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart.expect +++ b/packages/go_router_builder/test_inputs/stateful_shell_route_data.dart.expect @@ -1,9 +1,7 @@ RouteBase get $statefulShellRouteNoConstConstructor => StatefulShellRouteData.$route( factory: $StatefulShellRouteNoConstConstructorExtension._fromState, - branches: [ - StatefulShellBranchData.$branch(), - ], + branches: [StatefulShellBranchData.$branch()], ); extension $StatefulShellRouteNoConstConstructorExtension @@ -15,14 +13,12 @@ extension $StatefulShellRouteNoConstConstructorExtension RouteBase get $statefulShellRouteWithConstConstructor => StatefulShellRouteData.$route( factory: $StatefulShellRouteWithConstConstructorExtension._fromState, - branches: [ - StatefulShellBranchData.$branch(), - ], + branches: [StatefulShellBranchData.$branch()], ); extension $StatefulShellRouteWithConstConstructorExtension on StatefulShellRouteWithConstConstructor { static StatefulShellRouteWithConstConstructor _fromState( - GoRouterState state) => - const StatefulShellRouteWithConstConstructor(); + GoRouterState state, + ) => const StatefulShellRouteWithConstConstructor(); } diff --git a/packages/go_router_builder/test_inputs/typed_query_parameter.dart.expect b/packages/go_router_builder/test_inputs/typed_query_parameter.dart.expect index 2011cff037e0..1708d26e2c57 100644 --- a/packages/go_router_builder/test_inputs/typed_query_parameter.dart.expect +++ b/packages/go_router_builder/test_inputs/typed_query_parameter.dart.expect @@ -1,5 +1,6 @@ RouteBase get $overriddenParameterNameRoute => GoRouteData.$route( path: '/typed-go-route-parameter', + hasOverriddenOnExit: false, factory: $OverriddenParameterNameRoute._fromState, );