Skip to content

Commit c9347b8

Browse files
authored
[go_router] Fix return type of current state getter to be non-nullable (#8173)
The `state` getter returns a `GoRouterState?`, but I don't think it needs to be nullable since `currentConfiguration.last.buildState()` never returns `null`. I'm not sure if it is nullable on purpose for some changes planned in the Future. If there is a reason, it might be better to add a comment about it. Otherwise, it is just inconvenient that a null check is necessary.
1 parent 913c949 commit c9347b8

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 14.7.1
2+
3+
- Fixes return type of current state getter on `GoRouter` and `GoRouterDelegate` to be non-nullable.
4+
15
## 14.7.0
26

37
- Adds fragment support to GoRouter, enabling direct specification and automatic handling of fragments in routes.
@@ -11,7 +15,6 @@
1115
- Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
1216
- Updates readme.
1317

14-
1518
## 14.6.2
1619

1720
- Replaces deprecated collection method usage.

packages/go_router/lib/src/delegate.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
182182

183183
/// The top [GoRouterState], the state of the route that was
184184
/// last used in either [GoRouter.go] or [GoRouter.push].
185-
GoRouterState? get state => currentConfiguration.last
185+
GoRouterState get state => currentConfiguration.last
186186
.buildState(_configuration, currentConfiguration);
187187

188188
/// For use by the Router architecture as part of the RouterDelegate.

packages/go_router/lib/src/router.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class GoRouter implements RouterConfig<RouteMatchList> {
261261
/// Accessing this property via GoRouter.of(context).state will not
262262
/// cause rebuild if the state has changed, consider using
263263
/// GoRouterState.of(context) instead.
264-
GoRouterState? get state => routerDelegate.state;
264+
GoRouterState get state => routerDelegate.state;
265265

266266
/// Whether the imperative API affects browser URL bar.
267267
///

packages/go_router/pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: go_router
22
description: A declarative router for Flutter based on Navigation 2 supporting
33
deep linking, data-driven routes and more
4-
version: 14.7.0
5-
4+
version: 14.7.1
65
repository: https://github.com/flutter/packages/tree/main/packages/go_router
76
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
87

packages/go_router/test/go_router_test.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6030,39 +6030,39 @@ void main() {
60306030
await tester.pumpAndSettle();
60316031

60326032
GoRouterState? state = router.state;
6033-
expect(state?.name, 'home');
6034-
expect(state?.fullPath, '/');
6033+
expect(state.name, 'home');
6034+
expect(state.fullPath, '/');
60356035

60366036
router.go('/books');
60376037
await tester.pumpAndSettle();
60386038
state = router.state;
6039-
expect(state?.name, 'books');
6040-
expect(state?.fullPath, '/books');
6039+
expect(state.name, 'books');
6040+
expect(state.fullPath, '/books');
60416041

60426042
router.push('/boats');
60436043
await tester.pumpAndSettle();
60446044
state = router.state;
6045-
expect(state?.name, 'boats');
6046-
expect(state?.fullPath, '/boats');
6045+
expect(state.name, 'boats');
6046+
expect(state.fullPath, '/boats');
60476047

60486048
router.pop();
60496049
await tester.pumpAndSettle();
60506050
state = router.state;
6051-
expect(state?.name, 'books');
6052-
expect(state?.fullPath, '/books');
6051+
expect(state.name, 'books');
6052+
expect(state.fullPath, '/books');
60536053

60546054
router.go('/tulips');
60556055
await tester.pumpAndSettle();
60566056
state = router.state;
6057-
expect(state?.name, 'tulips');
6058-
expect(state?.fullPath, '/tulips');
6057+
expect(state.name, 'tulips');
6058+
expect(state.fullPath, '/tulips');
60596059

60606060
router.go('/books');
60616061
router.push('/tulips');
60626062
await tester.pumpAndSettle();
60636063
state = router.state;
6064-
expect(state?.name, 'tulips');
6065-
expect(state?.fullPath, '/tulips');
6064+
expect(state.name, 'tulips');
6065+
expect(state.fullPath, '/tulips');
60666066
});
60676067

60686068
testWidgets('should allow route paths without leading /',

0 commit comments

Comments
 (0)