Skip to content

Commit bf82745

Browse files
authored
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 flutter/flutter#106164 * fix: version * fix: changelog * fix: that was a typo * fix: That was a typo * feat: add test flutter/flutter#106164 * fix: after merge * feat: add test, check call redirect
1 parent 4f83ae3 commit bf82745

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
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+
## 4.2.5
2+
3+
- Fixes a bug where calling extra parameter is always null in route level redirect callback
4+
15
## 4.2.4
26

37
- Rewrites Readme and examples.

packages/go_router/lib/src/redirection.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ RouteMatchList redirect(RouteMatchList prevMatchList,
7878
name: top.route.name,
7979
path: top.route.path,
8080
fullpath: top.fullpath,
81+
extra: top.extra,
8182
params: top.decodedParams,
8283
queryParams: top.queryParams,
8384
),

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: 4.2.4
4+
version: 4.2.5
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/go_router_test.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,54 @@ void main() {
11701170
(router.screenFor(matches.first) as TestErrorScreen).ex, isNotNull);
11711171
log.info((router.screenFor(matches.first) as TestErrorScreen).ex);
11721172
});
1173+
1174+
testWidgets('extra not null in redirect', (WidgetTester tester) async {
1175+
bool isCallTopRedirect = false;
1176+
bool isCallRouteRedirect = false;
1177+
1178+
final List<GoRoute> routes = <GoRoute>[
1179+
GoRoute(
1180+
name: 'home',
1181+
path: '/',
1182+
builder: (BuildContext context, GoRouterState state) =>
1183+
const HomeScreen(),
1184+
routes: <GoRoute>[
1185+
GoRoute(
1186+
name: 'login',
1187+
path: 'login',
1188+
builder: (BuildContext context, GoRouterState state) {
1189+
return const LoginScreen();
1190+
},
1191+
redirect: (GoRouterState state) {
1192+
isCallRouteRedirect = true;
1193+
expect(state.extra, isNotNull);
1194+
return null;
1195+
},
1196+
routes: <GoRoute>[],
1197+
),
1198+
],
1199+
),
1200+
];
1201+
1202+
final GoRouter router = await createRouter(
1203+
routes,
1204+
tester,
1205+
redirect: (GoRouterState state) {
1206+
if (state.location == '/login') {
1207+
isCallTopRedirect = true;
1208+
expect(state.extra, isNotNull);
1209+
}
1210+
1211+
return null;
1212+
},
1213+
);
1214+
1215+
router.go('/login', extra: 1);
1216+
await tester.pump();
1217+
1218+
expect(isCallTopRedirect, true);
1219+
expect(isCallRouteRedirect, true);
1220+
});
11731221
});
11741222

11751223
group('initial location', () {

0 commit comments

Comments
 (0)