From a81ec3522a3552c9dafd51b49af8b9d311a2bca1 Mon Sep 17 00:00:00 2001 From: Kabo <20254485+kaboc@users.noreply.github.com> Date: Mon, 25 Nov 2024 23:18:49 +0900 Subject: [PATCH 1/3] Fix return type of current state getter to be non-nullable --- packages/go_router/lib/src/delegate.dart | 2 +- packages/go_router/lib/src/router.dart | 2 +- packages/go_router/test/go_router_test.dart | 24 ++++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/go_router/lib/src/delegate.dart b/packages/go_router/lib/src/delegate.dart index 56326e4faf7..3b90297be28 100644 --- a/packages/go_router/lib/src/delegate.dart +++ b/packages/go_router/lib/src/delegate.dart @@ -182,7 +182,7 @@ class GoRouterDelegate extends RouterDelegate /// 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. diff --git a/packages/go_router/lib/src/router.dart b/packages/go_router/lib/src/router.dart index 11f40f505ca..da9f7282867 100644 --- a/packages/go_router/lib/src/router.dart +++ b/packages/go_router/lib/src/router.dart @@ -261,7 +261,7 @@ class GoRouter implements RouterConfig { /// 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. /// diff --git a/packages/go_router/test/go_router_test.dart b/packages/go_router/test/go_router_test.dart index 2e92c560a67..d98f10711c5 100644 --- a/packages/go_router/test/go_router_test.dart +++ b/packages/go_router/test/go_router_test.dart @@ -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 /', From 22be5c6524d8c6870a8dd90054a5bf12ec7233e2 Mon Sep 17 00:00:00 2001 From: Kabo <20254485+kaboc@users.noreply.github.com> Date: Mon, 25 Nov 2024 23:31:50 +0900 Subject: [PATCH 2/3] Update version --- packages/go_router/CHANGELOG.md | 4 ++++ packages/go_router/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index b1487a22f6c..b2e75b690ca 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 14.6.2 + +- Fixes return type of current state getter on `GoRouter` and `GoRouterDelegate` to be non-nullable. + ## 14.6.1 - Fixed `PopScope`, and `WillPopScop` was not handled properly in the Root routes. diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 4215e95dfda..a5e2e26b3cf 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -1,7 +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.6.1 +version: 14.6.2 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 From f1142160f403b535bc5430128a7d52f0a1dd75c5 Mon Sep 17 00:00:00 2001 From: Hannah Jin Date: Wed, 18 Dec 2024 13:03:46 -0800 Subject: [PATCH 3/3] Update pubspec.yaml --- packages/go_router/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 1113c4cbea9..f57e3841bb2 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -1,7 +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.6.2 +version: 14.6.3 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