Skip to content

[go_router] Fix return type of current state getter to be non-nullable #8173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
5 changes: 4 additions & 1 deletion packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 14.7.1

- Fixes return type of current state getter on `GoRouter` and `GoRouterDelegate` to be non-nullable.

## 14.7.0

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


## 14.6.2

- Replaces deprecated collection method usage.
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/lib/src/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>

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

/// For use by the Router architecture as part of the RouterDelegate.
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class GoRouter implements RouterConfig<RouteMatchList> {
/// Accessing this property via GoRouter.of(context).state will not
/// cause rebuild if the state has changed, consider using
/// GoRouterState.of(context) instead.
GoRouterState? get state => routerDelegate.state;
GoRouterState get state => routerDelegate.state;

/// Whether the imperative API affects browser URL bar.
///
Expand Down
3 changes: 1 addition & 2 deletions packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +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.0

version: 14.7.1
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

Expand Down
24 changes: 12 additions & 12 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6030,39 +6030,39 @@ void main() {
await tester.pumpAndSettle();

GoRouterState? state = router.state;
expect(state?.name, 'home');
expect(state?.fullPath, '/');
expect(state.name, 'home');
expect(state.fullPath, '/');

router.go('/books');
await tester.pumpAndSettle();
state = router.state;
expect(state?.name, 'books');
expect(state?.fullPath, '/books');
expect(state.name, 'books');
expect(state.fullPath, '/books');

router.push('/boats');
await tester.pumpAndSettle();
state = router.state;
expect(state?.name, 'boats');
expect(state?.fullPath, '/boats');
expect(state.name, 'boats');
expect(state.fullPath, '/boats');

router.pop();
await tester.pumpAndSettle();
state = router.state;
expect(state?.name, 'books');
expect(state?.fullPath, '/books');
expect(state.name, 'books');
expect(state.fullPath, '/books');

router.go('/tulips');
await tester.pumpAndSettle();
state = router.state;
expect(state?.name, 'tulips');
expect(state?.fullPath, '/tulips');
expect(state.name, 'tulips');
expect(state.fullPath, '/tulips');

router.go('/books');
router.push('/tulips');
await tester.pumpAndSettle();
state = router.state;
expect(state?.name, 'tulips');
expect(state?.fullPath, '/tulips');
expect(state.name, 'tulips');
expect(state.fullPath, '/tulips');
});

testWidgets('should allow route paths without leading /',
Expand Down
Loading