diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 096e927331c..e4ea9f6782c 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.6.0 + +* Adds support for passing observers to the StatefulShellBranch for the nested Navigator. + ## 2.5.1 - Updates examples to use uri.path instead of uri.toString() for accessing the current location. diff --git a/packages/go_router_builder/lib/src/route_config.dart b/packages/go_router_builder/lib/src/route_config.dart index 599ff124f15..0cfa7a3928c 100644 --- a/packages/go_router_builder/lib/src/route_config.dart +++ b/packages/go_router_builder/lib/src/route_config.dart @@ -146,6 +146,7 @@ class StatefulShellBranchConfig extends RouteBaseConfig { required this.navigatorKey, required super.routeDataClass, required super.parent, + required this.observers, this.restorationScopeId, this.initialLocation, }) : super._(); @@ -159,6 +160,9 @@ class StatefulShellBranchConfig extends RouteBaseConfig { /// The initial route. final String? initialLocation; + /// The navigator observers. + final String? observers; + @override Iterable classDeclarations() => []; @@ -168,7 +172,8 @@ class StatefulShellBranchConfig extends RouteBaseConfig { String get routeConstructorParameters => '${navigatorKey == null ? '' : 'navigatorKey: $navigatorKey,'}' '${restorationScopeId == null ? '' : 'restorationScopeId: $restorationScopeId,'}' - '${initialLocation == null ? '' : 'initialLocation: $initialLocation,'}'; + '${initialLocation == null ? '' : 'initialLocation: $initialLocation,'}' + '${observers == null ? '' : 'observers: $observers,'}'; @override String get routeDataClassName => 'StatefulShellBranchData'; @@ -521,6 +526,10 @@ abstract class RouteBaseConfig { classElement, parameterName: r'$initialLocation', ), + observers: _generateParameterGetterCode( + classElement, + parameterName: r'$observers', + ), ); 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 b552204767a..c5a656334ff 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -2,12 +2,13 @@ name: go_router_builder description: >- A builder that supports generated strongly-typed route helpers for package:go_router -version: 2.5.1 +version: 2.6.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 environment: sdk: ^3.1.0 + flutter: ">=3.13.0" dependencies: analyzer: ">=5.2.0 <7.0.0" @@ -23,6 +24,8 @@ dependencies: dev_dependencies: build_test: ^2.1.7 dart_style: 2.3.2 + flutter: + sdk: flutter go_router: ^10.0.0 test: ^1.20.0 diff --git a/packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart b/packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart new file mode 100644 index 00000000000..07fac002af8 --- /dev/null +++ b/packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart @@ -0,0 +1,14 @@ +// 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:flutter/widgets.dart'; +import 'package:go_router/go_router.dart'; + +@TypedStatefulShellBranch() +class StatefulShellBranchWithObserversData extends StatefulShellBranchData { + const StatefulShellBranchWithObserversData(); + + static const String $initialLocation = '/main/second-tab'; + static const List $observers = []; +} diff --git a/packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart.expect b/packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart.expect new file mode 100644 index 00000000000..d851a3f1ffb --- /dev/null +++ b/packages/go_router_builder/test_inputs/statefull_shell_branch_with_observers_data.dart.expect @@ -0,0 +1,5 @@ +RouteBase get $statefulShellBranchWithObserversData => + StatefulShellBranchData.$branch( + initialLocation: StatefulShellBranchWithObserversData.$initialLocation, + observers: StatefulShellBranchWithObserversData.$observers, + );