From 5532775b197fa29dd0ae490663f45189b41c804c Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Fri, 29 Jul 2022 10:13:09 -0700 Subject: [PATCH] Add onTapOutside to TextFormField (#108629) --- .../lib/src/material/text_form_field.dart | 2 ++ .../test/material/text_form_field_test.dart | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index bf6d9563f18b..1b1db946cae2 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -125,6 +125,7 @@ class TextFormField extends FormField { int? maxLength, ValueChanged? onChanged, GestureTapCallback? onTap, + TapRegionCallback? onTapOutside, VoidCallback? onEditingComplete, ValueChanged? onFieldSubmitted, super.onSaved, @@ -216,6 +217,7 @@ class TextFormField extends FormField { maxLength: maxLength, onChanged: onChangedHandler, onTap: onTap, + onTapOutside: onTapOutside, onEditingComplete: onEditingComplete, onSubmitted: onFieldSubmitted, inputFormatters: inputFormatters, diff --git a/packages/flutter/test/material/text_form_field_test.dart b/packages/flutter/test/material/text_form_field_test.dart index 3436b7301c92..a44716cafa62 100644 --- a/packages/flutter/test/material/text_form_field_test.dart +++ b/packages/flutter/test/material/text_form_field_test.dart @@ -728,6 +728,36 @@ void main() { expect(tapCount, 3); }); + testWidgets('onTapOutside is called upon tap outside', (WidgetTester tester) async { + int tapOutsideCount = 0; + await tester.pumpWidget( + MaterialApp( + home: Material( + child: Center( + child: Column( + children: [ + const Text('Outside'), + TextFormField( + onTapOutside: (PointerEvent event) { + tapOutsideCount += 1; + }, + ), + ], + ), + ), + ), + ), + ); + await tester.pump(); // Wait for autofocus to take effect. + + expect(tapOutsideCount, 0); + await tester.tap(find.byType(TextFormField)); + await tester.tap(find.text('Outside')); + await tester.tap(find.text('Outside')); + await tester.tap(find.text('Outside')); + expect(tapOutsideCount, 3); + }); + // Regression test for https://github.com/flutter/flutter/issues/54472. testWidgets('reset resets the text fields value to the initialValue', (WidgetTester tester) async { await tester.pumpWidget(