diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index a8a79ca41d2..f34047da732 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.8.0 + +- Adds support for passing `preload` parameter to `StatefulShellBranchData`. + ## 2.7.5 - Fixes trailing `?` in the location when a go route has an empty default value. diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index b35ce4abb4f..94212051ff0 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -149,6 +149,7 @@ class StatefulShellBranchConfig extends RouteBaseConfig { required this.observers, this.restorationScopeId, this.initialLocation, + this.preload, }) : super._(); /// The command for calling the navigator key getter from the ShellRouteData. @@ -163,6 +164,9 @@ class StatefulShellBranchConfig extends RouteBaseConfig { /// The navigator observers. final String? observers; + /// The preload parameter. + final String? preload; + @override Iterable classDeclarations() => []; @@ -173,7 +177,8 @@ class StatefulShellBranchConfig extends RouteBaseConfig { '${navigatorKey == null ? '' : 'navigatorKey: $navigatorKey,'}' '${restorationScopeId == null ? '' : 'restorationScopeId: $restorationScopeId,'}' '${initialLocation == null ? '' : 'initialLocation: $initialLocation,'}' - '${observers == null ? '' : 'observers: $observers,'}'; + '${observers == null ? '' : 'observers: $observers,'}' + '${preload == null ? '' : 'preload: $preload,'}'; @override String get routeDataClassName => 'StatefulShellBranchData'; @@ -532,6 +537,10 @@ abstract class RouteBaseConfig { classElement, parameterName: r'$observers', ), + preload: _generateParameterGetterCode( + classElement, + parameterName: r'$preload', + ), ); case 'TypedGoRoute': final ConstantReader pathValue = reader.read('path'); diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index 6c2ab45cb38..113a88619f1 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.7.5 +version: 2.8.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 @@ -26,7 +26,7 @@ dev_dependencies: dart_style: '>=2.3.7 <4.0.0' flutter: sdk: flutter - go_router: ^14.0.0 + go_router: ^14.8.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/stateful_shell_branch_with_preload_data.dart b/packages/go_router_builder/test_inputs/stateful_shell_branch_with_preload_data.dart new file mode 100644 index 00000000000..ae33741a848 --- /dev/null +++ b/packages/go_router_builder/test_inputs/stateful_shell_branch_with_preload_data.dart @@ -0,0 +1,13 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:go_router/go_router.dart'; + +@TypedStatefulShellBranch() +class StatefulShellBranchWithPreloadData extends StatefulShellBranchData { + const StatefulShellBranchWithPreloadData(); + + static const String $initialLocation = '/main/second-tab'; + static const bool $preload = true; +} diff --git a/packages/go_router_builder/test_inputs/stateful_shell_branch_with_preload_data.dart.expect b/packages/go_router_builder/test_inputs/stateful_shell_branch_with_preload_data.dart.expect new file mode 100644 index 00000000000..43bb9645f1e --- /dev/null +++ b/packages/go_router_builder/test_inputs/stateful_shell_branch_with_preload_data.dart.expect @@ -0,0 +1,5 @@ +RouteBase get $statefulShellBranchWithPreloadData => + StatefulShellBranchData.$branch( + initialLocation: StatefulShellBranchWithPreloadData.$initialLocation, + preload: StatefulShellBranchWithPreloadData.$preload, + );