Skip to content

Commit 990e799

Browse files
Philclaude
andcommitted
test: canary for a selection area over a page never laid out (flutter/flutter#119772)
A deep link stacks its pages at once, so the covered ones are built but never laid out. A SelectionArea around the router sorts every selectable by its place on screen, the covered page's Text included, and asserts that its RenderBox was not laid out. It reproduces in auto_route as in plain Flutter; laying out covered pages would mean building them on screen, the same limit as flutter/flutter#194447. The canary pins the assertion. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 14f3959 commit 990e799

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import 'dart:async';
2+
3+
import 'package:auto_route/auto_route.dart';
4+
import 'package:flutter_test/flutter_test.dart';
5+
import 'package:material_ui/material_ui.dart';
6+
7+
import 'router_test_utils.dart';
8+
9+
// Canary for Flutter bug https://github.com/flutter/flutter/issues/119772.
10+
// Setup: ShellRoute wraps a nested AutoRouter in a SelectionArea. Plain
11+
// Flutter, with a SelectableRegion around a Navigator given two pages at
12+
// once, fails the same way.
13+
// Steps: open the app on the deep link /foreground, which stacks
14+
// ForegroundRoute on BackgroundRoute in the nested router at once.
15+
// Today BackgroundRoute is built but never laid out, since it is covered from
16+
// the start. The SelectionArea sorts every selectable by its place on screen,
17+
// including BackgroundRoute's Text, and asserts "RenderBox was not laid out"
18+
// when it measures it. auto_route cannot lay out a covered page without
19+
// building it on screen.
20+
// If this test fails after a Flutter upgrade, the selection area no longer
21+
// measures a page that was never laid out: drop this canary.
22+
void main() {
23+
testWidgets('a selection area over a page never laid out asserts when it sorts its selectables', (tester) async {
24+
final router = RootStackRouter.build(
25+
routes: [
26+
AutoRoute(
27+
path: '/',
28+
page: PageInfo('ShellRoute', builder: (_) => const SelectionArea(child: AutoRouter())),
29+
children: [
30+
AutoRoute(
31+
path: '',
32+
page: PageInfo('BackgroundRoute', builder: (_) => const Scaffold(body: Text('background'))),
33+
),
34+
AutoRoute(
35+
path: 'foreground',
36+
page: PageInfo('ForegroundRoute', builder: (_) => const Scaffold(body: Text('foreground'))),
37+
),
38+
],
39+
),
40+
],
41+
);
42+
final errors = <Object>[];
43+
await runZonedGuarded(
44+
() => pumpRouterApp(tester, router, initialLink: '/foreground'),
45+
(error, _) => errors.add(error),
46+
);
47+
expect(router.innerRouterOf<StackRouter>('ShellRoute')!.stack.map((page) => page.name), [
48+
'BackgroundRoute',
49+
'ForegroundRoute',
50+
]);
51+
expect(find.text('foreground'), findsOneWidget);
52+
expect(errors, isNotEmpty);
53+
expect('${errors.first}', contains('RenderBox was not laid out'));
54+
});
55+
}

0 commit comments

Comments
 (0)