From 1b40c01079fabd7053303e6c856258e214bbbdc1 Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed Sameh Date: Tue, 11 Nov 2025 02:47:14 +0200 Subject: [PATCH] Make sure that a TextFormField doesn't crash in 0x0 environment (#178233) This is my attempt to handle https://github.com/flutter/flutter/issues/6537 for the TextFormField widget. --- .../test/material/text_form_field_test.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/flutter/test/material/text_form_field_test.dart b/packages/flutter/test/material/text_form_field_test.dart index 7eb3c20be12..833628fcaba 100644 --- a/packages/flutter/test/material/text_form_field_test.dart +++ b/packages/flutter/test/material/text_form_field_test.dart @@ -1875,4 +1875,21 @@ void main() { .copyWith(enabled: true, hintMaxLines: 1); expect(decorator.decoration, expectedDecoration); }); + + testWidgets('TextFormField does not crash at zero area', (WidgetTester tester) async { + tester.view.physicalSize = Size.zero; + final TextEditingController controller = TextEditingController(text: 'X'); + addTearDown(tester.view.reset); + addTearDown(controller.dispose); + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Center(child: TextFormField(controller: controller)), + ), + ), + ); + expect(tester.getSize(find.byType(TextFormField)), Size.zero); + controller.selection = const TextSelection.collapsed(offset: 0); + tester.pump(); + }); }