diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index d73a3e682e8..8c7bf3ee834 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,7 +1,8 @@ -## NEXT +## 2.5.0 * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. * Updates dependencies to require `analyzer` 5.2.0 or later. +* Adds `restorationScopeId` to `ShellRouteData`. ## 2.4.1 diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index cdfdb03e14d..599ff124f15 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -42,6 +42,7 @@ class ShellRouteConfig extends RouteBaseConfig { required super.routeDataClass, required this.observers, required super.parent, + required this.restorationScopeId, }) : super._(); /// The command for calling the navigator key getter from the ShellRouteData. @@ -53,6 +54,9 @@ class ShellRouteConfig extends RouteBaseConfig { /// The navigator observers. final String? observers; + /// The restoration scope id. + final String? restorationScopeId; + @override Iterable classDeclarations() { if (routeDataClass.unnamedConstructor == null) { @@ -77,7 +81,8 @@ class ShellRouteConfig extends RouteBaseConfig { String get routeConstructorParameters => '${navigatorKey == null ? '' : 'navigatorKey: $navigatorKey,'}' '${parentNavigatorKey == null ? '' : 'parentNavigatorKey: $parentNavigatorKey,'}' - '${observers == null ? '' : 'observers: $observers,'}'; + '${observers == null ? '' : 'observers: $observers,'}' + '${restorationScopeId == null ? '' : 'restorationScopeId: $restorationScopeId,'}'; @override String get factorConstructorParameters => @@ -478,6 +483,10 @@ abstract class RouteBaseConfig { classElement, parameterName: r'$observers', ), + restorationScopeId: _generateParameterGetterCode( + classElement, + parameterName: r'$restorationScopeId', + ), ); case 'TypedStatefulShellRoute': value = StatefulShellRouteConfig._( diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 1fc254577ff..a3ffb517965 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -2,7 +2,7 @@ name: go_router_builder description: >- A builder that supports generated strongly-typed route helpers for package:go_router -version: 2.4.1 +version: 2.5.0 repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22 diff --git a/packages/go_router_builder/test_inputs/shell_route_data.dart b/packages/go_router_builder/test_inputs/shell_route_data.dart index 43f2b28498b..b4839d98726 100644 --- a/packages/go_router_builder/test_inputs/shell_route_data.dart +++ b/packages/go_router_builder/test_inputs/shell_route_data.dart @@ -15,3 +15,12 @@ class ShellRouteNoConstConstructor extends ShellRouteData {} class ShellRouteWithConstConstructor extends ShellRouteData { const ShellRouteWithConstConstructor(); } + +@TypedShellRoute( + routes: >[], +) +class ShellRouteWithRestorationScopeId extends ShellRouteData { + const ShellRouteWithRestorationScopeId(); + + static const String $restorationScopeId = 'shellRouteWithRestorationScopeId'; +} 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 b99dd5176be..a5778302090 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 @@ -17,3 +17,14 @@ extension $ShellRouteWithConstConstructorExtension static ShellRouteWithConstConstructor _fromState(GoRouterState state) => const ShellRouteWithConstConstructor(); } + +RouteBase get $shellRouteWithRestorationScopeId => ShellRouteData.$route( + restorationScopeId: ShellRouteWithRestorationScopeId.$restorationScopeId, + factory: $ShellRouteWithRestorationScopeIdExtension._fromState, + ); + +extension $ShellRouteWithRestorationScopeIdExtension + on ShellRouteWithRestorationScopeId { + static ShellRouteWithRestorationScopeId _fromState(GoRouterState state) => + const ShellRouteWithRestorationScopeId(); +} \ No newline at end of file