@@ -30,6 +30,30 @@ class _ShellRouteDataBuilder extends ShellRouteData {
3030 );
3131}
3232
33+ class _ShellRouteDataWithKey extends ShellRouteData {
34+ const _ShellRouteDataWithKey (this .key);
35+
36+ final Key key;
37+
38+ @override
39+ Widget builder (
40+ BuildContext context,
41+ GoRouterState state,
42+ Widget navigator,
43+ ) =>
44+ SizedBox (
45+ key: key,
46+ child: navigator,
47+ );
48+ }
49+
50+ class _GoRouteDataBuildWithKey extends GoRouteData {
51+ const _GoRouteDataBuildWithKey (this .key);
52+ final Key key;
53+ @override
54+ Widget build (BuildContext context, GoRouterState state) => SizedBox (key: key);
55+ }
56+
3357final GoRoute _goRouteDataBuild = GoRouteData .$route (
3458 path: '/build' ,
3559 factory : (GoRouterState state) => const _GoRouteDataBuild (),
@@ -211,6 +235,63 @@ void main() {
211235 },
212236 );
213237
238+ testWidgets (
239+ 'It should build the page from the overridden build method' ,
240+ (WidgetTester tester) async {
241+ final GlobalKey <NavigatorState > root = GlobalKey <NavigatorState >();
242+ final GlobalKey <NavigatorState > inner = GlobalKey <NavigatorState >();
243+ final GoRouter goRouter = GoRouter (
244+ navigatorKey: root,
245+ initialLocation: '/child/test' ,
246+ routes: < RouteBase > [
247+ ShellRouteData .$route (
248+ factory : (GoRouterState state) =>
249+ const _ShellRouteDataWithKey (Key ('under-shell' )),
250+ routes: < RouteBase > [
251+ GoRouteData .$route (
252+ path: '/child' ,
253+ factory : (GoRouterState state) =>
254+ const _GoRouteDataBuildWithKey (Key ('under' )),
255+ routes: < RouteBase > [
256+ ShellRouteData .$route (
257+ factory : (GoRouterState state) =>
258+ const _ShellRouteDataWithKey (Key ('above-shell' )),
259+ navigatorKey: inner,
260+ parentNavigatorKey: root,
261+ routes: < RouteBase > [
262+ GoRouteData .$route (
263+ parentNavigatorKey: inner,
264+ path: 'test' ,
265+ factory : (GoRouterState state) =>
266+ const _GoRouteDataBuildWithKey (Key ('above' )),
267+ ),
268+ ],
269+ ),
270+ ]),
271+ ],
272+ ),
273+ ],
274+ );
275+ await tester.pumpWidget (MaterialApp .router (
276+ routerConfig: goRouter,
277+ ));
278+ expect (find.byKey (const Key ('under-shell' )), findsNothing);
279+ expect (find.byKey (const Key ('under' )), findsNothing);
280+
281+ expect (find.byKey (const Key ('above-shell' )), findsOneWidget);
282+ expect (find.byKey (const Key ('above' )), findsOneWidget);
283+
284+ goRouter.pop ();
285+ await tester.pumpAndSettle ();
286+
287+ expect (find.byKey (const Key ('under-shell' )), findsOneWidget);
288+ expect (find.byKey (const Key ('under' )), findsOneWidget);
289+
290+ expect (find.byKey (const Key ('above-shell' )), findsNothing);
291+ expect (find.byKey (const Key ('above' )), findsNothing);
292+ },
293+ );
294+
214295 testWidgets (
215296 'It should build the page from the overridden buildPage method' ,
216297 (WidgetTester tester) async {
@@ -257,6 +338,26 @@ void main() {
257338 expect (find.byKey (const Key ('page-builder' )), findsOneWidget);
258339 },
259340 );
341+
342+ test ('Can assign parent navigator key' , () {
343+ final GlobalKey <NavigatorState > key = GlobalKey <NavigatorState >();
344+ final StatefulShellRoute route = StatefulShellRouteData .$route (
345+ parentNavigatorKey: key,
346+ factory : (GoRouterState state) =>
347+ const _StatefulShellRouteDataPageBuilder (),
348+ branches: < StatefulShellBranch > [
349+ StatefulShellBranchData .$branch (
350+ routes: < RouteBase > [
351+ GoRouteData .$route (
352+ path: '/child' ,
353+ factory : (GoRouterState state) => const _GoRouteDataBuild (),
354+ ),
355+ ],
356+ ),
357+ ],
358+ );
359+ expect (route.parentNavigatorKey, key);
360+ });
260361 });
261362
262363 testWidgets (
0 commit comments