From 5df17acb1f852f6a3c1ad0b7fcd869bb09e13db0 Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Fri, 2 Aug 2019 10:34:39 -0700 Subject: [PATCH] add ontap to textformfield (#37403) --- .../lib/src/material/text_form_field.dart | 2 ++ .../test/material/text_form_field_test.dart | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index 9eb69b1d1c..3cc3aaa9ec 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -100,6 +100,7 @@ class TextFormField extends FormField { bool expands = false, int maxLength, ValueChanged onChanged, + GestureTapCallback onTap, VoidCallback onEditingComplete, ValueChanged onFieldSubmitted, FormFieldSetter onSaved, @@ -175,6 +176,7 @@ class TextFormField extends FormField { expands: expands, maxLength: maxLength, onChanged: onChangedHandler, + onTap: onTap, 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 8fe21d68ba..622eeb73be 100644 --- a/packages/flutter/test/material/text_form_field_test.dart +++ b/packages/flutter/test/material/text_form_field_test.dart @@ -280,4 +280,31 @@ void main() { await tester.pump(const Duration(milliseconds: 200)); expect(renderEditable, paintsExactlyCountTimes(#drawRect, 0)); }); + + testWidgets('onTap is called upon tap', (WidgetTester tester) async { + int tapCount = 0; + await tester.pumpWidget( + MaterialApp( + home: Material( + child: Center( + child: TextFormField( + onTap: () { + tapCount += 1; + }, + ), + ), + ), + ), + ); + + expect(tapCount, 0); + await tester.tap(find.byType(TextField)); + // Wait a bit so they're all single taps and not double taps. + await tester.pump(const Duration(milliseconds: 300)); + await tester.tap(find.byType(TextField)); + await tester.pump(const Duration(milliseconds: 300)); + await tester.tap(find.byType(TextField)); + await tester.pump(const Duration(milliseconds: 300)); + expect(tapCount, 3); + }); }