From 76f70d21da9c58da773ca7ebb044b2bbb8808c28 Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed Sameh Date: Thu, 19 Feb 2026 02:40:54 +0200 Subject: [PATCH] Handle#6537 first grouped tests (#182077) This is my attempt to handle https://github.com/flutter/flutter/issues/6537 for the following widgets: AnimatedOpacity AnimatedDefaultTextStyle AnimatedPhysicalModel AnimatedFractionallySizedBox InteractiveViewer LayoutBuilder ListWheelScrollView ListWheelViewport Localizations RawMagnifier ModalBarrier --------- Co-authored-by: Tong Mu --- .../test/cupertino/magnifier_test.dart | 14 ++++ .../widgets/implicit_animations_test.dart | 75 +++++++++++++++++++ .../test/widgets/interactive_viewer_test.dart | 12 +++ .../test/widgets/layout_builder_test.dart | 12 +++ .../widgets/list_wheel_scroll_view_test.dart | 6 +- .../test/widgets/localizations_test.dart | 18 +++++ .../test/widgets/modal_barrier_test.dart | 10 +++ 7 files changed, 146 insertions(+), 1 deletion(-) diff --git a/packages/flutter/test/cupertino/magnifier_test.dart b/packages/flutter/test/cupertino/magnifier_test.dart index ef3af4a9fe4..ebdae3221f8 100644 --- a/packages/flutter/test/cupertino/magnifier_test.dart +++ b/packages/flutter/test/cupertino/magnifier_test.dart @@ -370,4 +370,18 @@ void main() { ); expect(tester.getSize(find.byType(CupertinoMagnifier)), Size.zero); }); + + testWidgets('RawMagnifier does not crash at zero area', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox.shrink( + child: RawMagnifier(size: Size.square(2), child: Text('X')), + ), + ), + ), + ); + expect(tester.getSize(find.byType(RawMagnifier)), Size.zero); + }); } diff --git a/packages/flutter/test/widgets/implicit_animations_test.dart b/packages/flutter/test/widgets/implicit_animations_test.dart index 7c0983698b0..e3add209efe 100644 --- a/packages/flutter/test/widgets/implicit_animations_test.dart +++ b/packages/flutter/test/widgets/implicit_animations_test.dart @@ -713,6 +713,81 @@ void main() { await tester.pumpAndSettle(); expect(tester.getSize(find.byType(AnimatedRotation)), Size.zero); }); + + testWidgets('AnimatedOpacity does not crash at zero area', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + child: AnimatedOpacity(opacity: 0.5, duration: Duration(milliseconds: 300)), + ), + ), + ), + ); + await tester.pumpAndSettle(); + expect(tester.getSize(find.byType(AnimatedOpacity)), Size.zero); + }); + + testWidgets('AnimatedDefaultTextStyle does not crash at zero area', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox.shrink( + child: AnimatedDefaultTextStyle( + style: TextStyle(fontStyle: FontStyle.italic), + duration: Duration(milliseconds: 300), + child: Text('X'), + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + expect(tester.getSize(find.byType(AnimatedDefaultTextStyle)), Size.zero); + }); + + testWidgets('AnimatedPhysicalModel does not crash at zero area', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox.shrink( + child: AnimatedPhysicalModel( + color: Colors.teal, + shadowColor: Colors.tealAccent, + duration: Duration(milliseconds: 300), + child: Text('X'), + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + expect(tester.getSize(find.byType(AnimatedPhysicalModel)), Size.zero); + }); + + testWidgets('AnimatedFractionallySizedBox does not crash at zero area', ( + WidgetTester tester, + ) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox.shrink( + child: AnimatedFractionallySizedBox( + duration: Duration(milliseconds: 300), + widthFactor: 0.5, + heightFactor: 0.5, + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + expect(tester.getSize(find.byType(AnimatedFractionallySizedBox)), Size.zero); + }); } Future tapTest2and3( diff --git a/packages/flutter/test/widgets/interactive_viewer_test.dart b/packages/flutter/test/widgets/interactive_viewer_test.dart index ce7eded8c87..c3b33c0e030 100644 --- a/packages/flutter/test/widgets/interactive_viewer_test.dart +++ b/packages/flutter/test/widgets/interactive_viewer_test.dart @@ -1941,6 +1941,18 @@ void main() { expect(nearestPoint.y, moreOrLessEquals(10.8, epsilon: 0.1)); }); }); + + testWidgets('InteractiveViewer does not crash at zero area', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox.shrink(child: InteractiveViewer(child: const Text('X'))), + ), + ), + ); + expect(tester.getSize(find.byType(InteractiveViewer)), Size.zero); + }); } Rect _axisAlignedBoundingBox(Quad quad) { diff --git a/packages/flutter/test/widgets/layout_builder_test.dart b/packages/flutter/test/widgets/layout_builder_test.dart index 2f7537bb803..0f26351dfe0 100644 --- a/packages/flutter/test/widgets/layout_builder_test.dart +++ b/packages/flutter/test/widgets/layout_builder_test.dart @@ -38,6 +38,18 @@ void main() { expect(childBox.size, equals(const Size(50.0, 100.0))); }); + testWidgets('LayoutBuilder does not crash at zero area', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox.shrink(child: LayoutBuilder(builder: (_, _) => const Text('X'))), + ), + ), + ); + expect(tester.getSize(find.byType(LayoutBuilder)), Size.zero); + }); + testWidgets('SliverLayoutBuilder parent geometry', (WidgetTester tester) async { late SliverConstraints parentConstraints1; late SliverConstraints parentConstraints2; diff --git a/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart b/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart index d84d9d61790..6a5de4f79d4 100644 --- a/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart +++ b/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart @@ -2040,13 +2040,15 @@ void main() { }); // This is a regression test for https://github.com/flutter/flutter/issues/140780. + // and https://github.com/flutter/flutter/issues/6537. testWidgets( - 'ListWheelScrollView in an AnimatedContainer with zero height does not throw an error', + 'ListWheelScrollView in an AnimatedContainer with zero width and height does not throw an error', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( home: Scaffold( body: AnimatedContainer( + width: 0, height: 0, duration: Duration.zero, child: ListWheelScrollView( @@ -2059,6 +2061,8 @@ void main() { ); expect(tester.takeException(), isNull); + expect(tester.getSize(find.byType(ListWheelScrollView)), Size.zero); + expect(tester.getSize(find.byType(ListWheelViewport)), Size.zero); }, ); } diff --git a/packages/flutter/test/widgets/localizations_test.dart b/packages/flutter/test/widgets/localizations_test.dart index 5e98991f448..4b5e6bd0cef 100644 --- a/packages/flutter/test/widgets/localizations_test.dart +++ b/packages/flutter/test/widgets/localizations_test.dart @@ -210,6 +210,24 @@ void main() { expect(node3.getSemanticsData().locale, isNull); }); }); + + testWidgets('Localizations does not crash at zero area', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox.shrink( + child: Localizations( + locale: const Locale('fo'), + delegates: >[WidgetsLocalizationsDelegate()], + child: const Text('X'), + ), + ), + ), + ), + ); + expect(tester.getSize(find.byType(Localizations)), Size.zero); + }); } class FakeLocalizationsDelegate extends LocalizationsDelegate { diff --git a/packages/flutter/test/widgets/modal_barrier_test.dart b/packages/flutter/test/widgets/modal_barrier_test.dart index 58e5689d25a..cc6158cd5f8 100644 --- a/packages/flutter/test/widgets/modal_barrier_test.dart +++ b/packages/flutter/test/widgets/modal_barrier_test.dart @@ -498,6 +498,16 @@ void main() { TargetPlatform.android, }), ); + + testWidgets('ModalBarrier does not crash at zero area', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center(child: SizedBox.shrink(child: ModalBarrier())), + ), + ); + expect(tester.getSize(find.byType(ModalBarrier)), Size.zero); + }); }); group('AnimatedModalBarrier', () { testWidgets('prevents interactions with widgets behind it', (WidgetTester tester) async {