Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
11 changes: 10 additions & 1 deletion packages/go_router_builder/lib/src/route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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._();
Expand All @@ -159,6 +160,9 @@ class StatefulShellBranchConfig extends RouteBaseConfig {
/// The initial route.
final String? initialLocation;

/// The navigator observers.
final String? observers;

@override
Iterable<String> classDeclarations() => <String>[];

Expand All @@ -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';
Expand Down Expand Up @@ -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');
Expand Down
5 changes: 4 additions & 1 deletion packages/go_router_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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<StatefulShellBranchWithObserversData>()
class StatefulShellBranchWithObserversData extends StatefulShellBranchData {
const StatefulShellBranchWithObserversData();

static const String $initialLocation = '/main/second-tab';
static const List<NavigatorObserver> $observers = <NavigatorObserver>[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RouteBase get $statefulShellBranchWithObserversData =>
StatefulShellBranchData.$branch(
initialLocation: StatefulShellBranchWithObserversData.$initialLocation,
observers: StatefulShellBranchWithObserversData.$observers,
);