From 970d858458903fbefc3b4be6395494352c04c74e Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Sat, 8 Feb 2025 03:06:02 +0800 Subject: [PATCH] [go_router] Add `preload` parameter to `StatefulShellBranchData.$branch` (#8545) Part of https://github.com/flutter/flutter/issues/162055 The parameter will be used by `go_router_builder` --- packages/go_router/CHANGELOG.md | 4 ++++ packages/go_router/lib/src/route_data.dart | 2 ++ packages/go_router/pubspec.yaml | 2 +- packages/go_router/test/route_data_test.dart | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index d51aaf244a37..97d8dfe35c3a 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 14.8.0 + +- Adds `preload` parameter to `StatefulShellBranchData.$branch`. + ## 14.7.2 - Add missing `await` keyword to `onTap` callback in `navigation.md`. diff --git a/packages/go_router/lib/src/route_data.dart b/packages/go_router/lib/src/route_data.dart index afe6159cecb9..a088cc96652b 100644 --- a/packages/go_router/lib/src/route_data.dart +++ b/packages/go_router/lib/src/route_data.dart @@ -342,6 +342,7 @@ abstract class StatefulShellBranchData { List? observers, String? initialLocation, String? restorationScopeId, + bool preload = false, }) { return StatefulShellBranch( routes: routes, @@ -349,6 +350,7 @@ abstract class StatefulShellBranchData { observers: observers, initialLocation: initialLocation, restorationScopeId: restorationScopeId, + preload: preload, ); } } diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 204db07f029f..636d2637eb9e 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -1,7 +1,7 @@ name: go_router description: A declarative router for Flutter based on Navigation 2 supporting deep linking, data-driven routes and more -version: 14.7.2 +version: 14.8.0 repository: https://github.com/flutter/packages/tree/main/packages/go_router issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22 diff --git a/packages/go_router/test/route_data_test.dart b/packages/go_router/test/route_data_test.dart index 1da35a672b64..757b1b054dd6 100644 --- a/packages/go_router/test/route_data_test.dart +++ b/packages/go_router/test/route_data_test.dart @@ -420,6 +420,21 @@ void main() { }); }); + group('StatefulShellBranchData', () { + test('Can assign preload', () { + final StatefulShellBranch branch = StatefulShellBranchData.$branch( + preload: true, + routes: [ + GoRouteData.$route( + path: '/child', + factory: (GoRouterState state) => const _GoRouteDataBuild(), + ), + ], + ); + expect(branch.preload, true); + }); + }); + testWidgets( 'It should redirect using the overridden redirect method', (WidgetTester tester) async {