diff --git a/examples/api/lib/widgets/routes/route_observer.0.dart b/examples/api/lib/widgets/routes/route_observer.0.dart index fdb44fdce45..e1ce6adc72e 100644 --- a/examples/api/lib/widgets/routes/route_observer.0.dart +++ b/examples/api/lib/widgets/routes/route_observer.0.dart @@ -63,37 +63,39 @@ class _RouteObserverExampleState extends State @override Widget build(BuildContext context) { return Scaffold( - body: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - 'RouteObserver log:', - style: Theme.of(context).textTheme.headlineSmall, - ), - ConstrainedBox( - constraints: const BoxConstraints(maxHeight: 300.0), - child: ListView.builder( - itemCount: log.length, - itemBuilder: (BuildContext context, int index) { - if (log.isEmpty) { - return const SizedBox.shrink(); - } - return Text(log[index], textAlign: TextAlign.center); - }, + body: SingleChildScrollView( + child: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'RouteObserver log:', + style: Theme.of(context).textTheme.headlineSmall, ), - ), - OutlinedButton( - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) => const NextPage(), - ), - ); - }, - child: const Text('Go to next page'), - ), - ], + ConstrainedBox( + constraints: const BoxConstraints(maxHeight: 300.0), + child: ListView.builder( + itemCount: log.length, + itemBuilder: (BuildContext context, int index) { + if (log.isEmpty) { + return const SizedBox.shrink(); + } + return Text(log[index], textAlign: TextAlign.center); + }, + ), + ), + OutlinedButton( + onPressed: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) => const NextPage(), + ), + ); + }, + child: const Text('Go to next page'), + ), + ], + ), ), ), ); diff --git a/examples/api/test/widgets/routes/route_observer.0_test.dart b/examples/api/test/widgets/routes/route_observer.0_test.dart index 3c79c476398..91e60952e3a 100644 --- a/examples/api/test/widgets/routes/route_observer.0_test.dart +++ b/examples/api/test/widgets/routes/route_observer.0_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/rendering.dart'; import 'package:flutter_api_samples/widgets/routes/route_observer.0.dart' as example; import 'package:flutter_test/flutter_test.dart'; @@ -38,5 +39,24 @@ void main() { // Check the RouteObserver logs after the route is popped again. expect(find.text('didPush'), findsOneWidget); expect(find.text('didPopNext'), findsNWidgets(2)); + + // Check if any overflow or layout exceptions occurred. + expect(tester.takeException(), isNull); }); + + testWidgets( + 'RouteObserver example renders without overflow on small screens', + (WidgetTester tester) async { + // Set the screen size to a smaller value. + tester.view.physicalSize = const Size(200, 200); + addTearDown(tester.view.reset); + + // Build the RouteObserver example widget. + await tester.pumpWidget(const example.RouteObserverApp()); + await tester.pumpAndSettle(); + + // Verify there are no layout exceptions. + expect(tester.takeException(), isNull); + }, + ); }