Skip to content

Commit 76c651b

Browse files
ValentinVignalandroidseb
authored andcommitted
[go_router_builder] Add support for TypedStatefulShellBranch's preload (flutter#8587)
Fixes flutter/flutter#162055 Follow up of flutter#8545
1 parent 03f6d20 commit 76c651b

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

packages/go_router_builder/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.8.0
2+
3+
- Adds support for passing `preload` parameter to `StatefulShellBranchData`.
4+
15
## 2.7.5
26

37
- Fixes trailing `?` in the location when a go route has an empty default value.

packages/go_router_builder/lib/src/route_config.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class StatefulShellBranchConfig extends RouteBaseConfig {
149149
required this.observers,
150150
this.restorationScopeId,
151151
this.initialLocation,
152+
this.preload,
152153
}) : super._();
153154

154155
/// The command for calling the navigator key getter from the ShellRouteData.
@@ -163,6 +164,9 @@ class StatefulShellBranchConfig extends RouteBaseConfig {
163164
/// The navigator observers.
164165
final String? observers;
165166

167+
/// The preload parameter.
168+
final String? preload;
169+
166170
@override
167171
Iterable<String> classDeclarations() => <String>[];
168172

@@ -173,7 +177,8 @@ class StatefulShellBranchConfig extends RouteBaseConfig {
173177
'${navigatorKey == null ? '' : 'navigatorKey: $navigatorKey,'}'
174178
'${restorationScopeId == null ? '' : 'restorationScopeId: $restorationScopeId,'}'
175179
'${initialLocation == null ? '' : 'initialLocation: $initialLocation,'}'
176-
'${observers == null ? '' : 'observers: $observers,'}';
180+
'${observers == null ? '' : 'observers: $observers,'}'
181+
'${preload == null ? '' : 'preload: $preload,'}';
177182

178183
@override
179184
String get routeDataClassName => 'StatefulShellBranchData';
@@ -532,6 +537,10 @@ abstract class RouteBaseConfig {
532537
classElement,
533538
parameterName: r'$observers',
534539
),
540+
preload: _generateParameterGetterCode(
541+
classElement,
542+
parameterName: r'$preload',
543+
),
535544
);
536545
case 'TypedGoRoute':
537546
final ConstantReader pathValue = reader.read('path');

packages/go_router_builder/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: go_router_builder
22
description: >-
33
A builder that supports generated strongly-typed route helpers for
44
package:go_router
5-
version: 2.7.5
5+
version: 2.8.0
66
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
77
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22
88

@@ -26,7 +26,7 @@ dev_dependencies:
2626
dart_style: '>=2.3.7 <4.0.0'
2727
flutter:
2828
sdk: flutter
29-
go_router: ^14.0.0
29+
go_router: ^14.8.0
3030
leak_tracker_flutter_testing: ">=3.0.0"
3131
package_config: ^2.1.1
3232
pub_semver: ^2.1.5
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:go_router/go_router.dart';
6+
7+
@TypedStatefulShellBranch<StatefulShellBranchWithPreloadData>()
8+
class StatefulShellBranchWithPreloadData extends StatefulShellBranchData {
9+
const StatefulShellBranchWithPreloadData();
10+
11+
static const String $initialLocation = '/main/second-tab';
12+
static const bool $preload = true;
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RouteBase get $statefulShellBranchWithPreloadData =>
2+
StatefulShellBranchData.$branch(
3+
initialLocation: StatefulShellBranchWithPreloadData.$initialLocation,
4+
preload: StatefulShellBranchWithPreloadData.$preload,
5+
);

0 commit comments

Comments
 (0)