Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix return type of current state getter to be non-nullable
  • Loading branch information
kaboc committed Nov 25, 2024
commit a81ec3522a3552c9dafd51b49af8b9d311a2bca1
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
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