Skip to content

[go_router] Fixes missing state.extra in onException() #5077

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 1 commit into from
Oct 9, 2023
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/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 11.1.3

- Fixes missing state.extra in onException().

## 11.1.2

- Fixes a bug where the known routes and initial route were logged even when `debugLogDiagnostics` was set to `false`.
Expand Down
12 changes: 10 additions & 2 deletions packages/go_router/lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,14 @@ class RouteConfiguration {
}

/// The match used when there is an error during parsing.
static RouteMatchList _errorRouteMatchList(Uri uri, GoException exception) {
static RouteMatchList _errorRouteMatchList(
Uri uri,
GoException exception, {
Object? extra,
}) {
return RouteMatchList(
matches: const <RouteMatch>[],
extra: extra,
error: exception,
uri: uri,
pathParameters: const <String, String>{},
Expand Down Expand Up @@ -277,7 +282,10 @@ class RouteConfiguration {

if (matches == null) {
return _errorRouteMatchList(
uri, GoException('no routes for location: $uri'));
uri,
GoException('no routes for location: $uri'),
extra: extra,
);
}
return RouteMatchList(
matches: matches,
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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: 11.1.2
version: 11.1.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

Expand Down
15 changes: 15 additions & 0 deletions packages/go_router/test/exception_handling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ void main() {
expect(find.text('redirected /some-other-location'), findsOneWidget);
});

testWidgets('can redirect with extra', (WidgetTester tester) async {
final GoRouter router = await createRouter(<RouteBase>[
GoRoute(
path: '/error',
builder: (_, GoRouterState state) => Text('extra: ${state.extra}')),
], tester,
onException: (_, GoRouterState state, GoRouter router) =>
router.go('/error', extra: state.extra));
expect(find.text('extra: null'), findsOneWidget);

router.go('/some-other-location', extra: 'X');
await tester.pumpAndSettle();
expect(find.text('extra: X'), findsOneWidget);
});

testWidgets('stays on the same page if noop.', (WidgetTester tester) async {
final GoRouter router = await createRouter(
<RouteBase>[
Expand Down