fix: [go_router] Extra parameter is always null in route level redirect callback (#2404)
* fix: [go_router] Extra parameter is always null in route level redirect callback #106164
https://github.com/flutter/flutter/issues/106164
* fix: version
* fix: changelog
* fix: that was a typo
* fix: That was a typo
* feat: add test https://github.com/flutter/flutter/issues/106164
* fix: after merge
* feat: add test, check call redirect
diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md
index 86002df..9ceedfd 100644
--- a/packages/go_router/CHANGELOG.md
+++ b/packages/go_router/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 4.2.5
+
+- Fixes a bug where calling extra parameter is always null in route level redirect callback
+
## 4.2.4
- Rewrites Readme and examples.
diff --git a/packages/go_router/lib/src/redirection.dart b/packages/go_router/lib/src/redirection.dart
index 29b541d..400ef8b 100644
--- a/packages/go_router/lib/src/redirection.dart
+++ b/packages/go_router/lib/src/redirection.dart
@@ -78,6 +78,7 @@
name: top.route.name,
path: top.route.path,
fullpath: top.fullpath,
+ extra: top.extra,
params: top.decodedParams,
queryParams: top.queryParams,
),
diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml
index 722962e..9ba26d8 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: 4.2.4
+version: 4.2.5
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
diff --git a/packages/go_router/test/go_router_test.dart b/packages/go_router/test/go_router_test.dart
index 15b23c2..5758a58 100644
--- a/packages/go_router/test/go_router_test.dart
+++ b/packages/go_router/test/go_router_test.dart
@@ -1170,6 +1170,54 @@
(router.screenFor(matches.first) as TestErrorScreen).ex, isNotNull);
log.info((router.screenFor(matches.first) as TestErrorScreen).ex);
});
+
+ testWidgets('extra not null in redirect', (WidgetTester tester) async {
+ bool isCallTopRedirect = false;
+ bool isCallRouteRedirect = false;
+
+ final List<GoRoute> routes = <GoRoute>[
+ GoRoute(
+ name: 'home',
+ path: '/',
+ builder: (BuildContext context, GoRouterState state) =>
+ const HomeScreen(),
+ routes: <GoRoute>[
+ GoRoute(
+ name: 'login',
+ path: 'login',
+ builder: (BuildContext context, GoRouterState state) {
+ return const LoginScreen();
+ },
+ redirect: (GoRouterState state) {
+ isCallRouteRedirect = true;
+ expect(state.extra, isNotNull);
+ return null;
+ },
+ routes: <GoRoute>[],
+ ),
+ ],
+ ),
+ ];
+
+ final GoRouter router = await createRouter(
+ routes,
+ tester,
+ redirect: (GoRouterState state) {
+ if (state.location == '/login') {
+ isCallTopRedirect = true;
+ expect(state.extra, isNotNull);
+ }
+
+ return null;
+ },
+ );
+
+ router.go('/login', extra: 1);
+ await tester.pump();
+
+ expect(isCallTopRedirect, true);
+ expect(isCallRouteRedirect, true);
+ });
});
group('initial location', () {