Skip to content

Commit c0a6e0d

Browse files
[go_router] Fixes missing state.extra in onException() (flutter#5077)
This will help in knowing the extra Object passed when the _non-existing-location_ was asked. *List which issues are fixed by this PR. You must list at least one issue.* - The issue looks small, I will create it if needed by the maintainers *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* - No breaking changes
1 parent 3251585 commit c0a6e0d

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 11.1.3
2+
3+
- Fixes missing state.extra in onException().
4+
15
## 11.1.2
26

37
- Fixes a bug where the known routes and initial route were logged even when `debugLogDiagnostics` was set to `false`.

packages/go_router/lib/src/configuration.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,14 @@ class RouteConfiguration {
188188
}
189189

190190
/// The match used when there is an error during parsing.
191-
static RouteMatchList _errorRouteMatchList(Uri uri, GoException exception) {
191+
static RouteMatchList _errorRouteMatchList(
192+
Uri uri,
193+
GoException exception, {
194+
Object? extra,
195+
}) {
192196
return RouteMatchList(
193197
matches: const <RouteMatch>[],
198+
extra: extra,
194199
error: exception,
195200
uri: uri,
196201
pathParameters: const <String, String>{},
@@ -277,7 +282,10 @@ class RouteConfiguration {
277282

278283
if (matches == null) {
279284
return _errorRouteMatchList(
280-
uri, GoException('no routes for location: $uri'));
285+
uri,
286+
GoException('no routes for location: $uri'),
287+
extra: extra,
288+
);
281289
}
282290
return RouteMatchList(
283291
matches: matches,

packages/go_router/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +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: 11.1.2
4+
version: 11.1.3
55
repository: https://github.com/flutter/packages/tree/main/packages/go_router
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
77

packages/go_router/test/exception_handling_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ void main() {
7777
expect(find.text('redirected /some-other-location'), findsOneWidget);
7878
});
7979

80+
testWidgets('can redirect with extra', (WidgetTester tester) async {
81+
final GoRouter router = await createRouter(<RouteBase>[
82+
GoRoute(
83+
path: '/error',
84+
builder: (_, GoRouterState state) => Text('extra: ${state.extra}')),
85+
], tester,
86+
onException: (_, GoRouterState state, GoRouter router) =>
87+
router.go('/error', extra: state.extra));
88+
expect(find.text('extra: null'), findsOneWidget);
89+
90+
router.go('/some-other-location', extra: 'X');
91+
await tester.pumpAndSettle();
92+
expect(find.text('extra: X'), findsOneWidget);
93+
});
94+
8095
testWidgets('stays on the same page if noop.', (WidgetTester tester) async {
8196
final GoRouter router = await createRouter(
8297
<RouteBase>[

0 commit comments

Comments
 (0)