|
| 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