Add onTapOutside to TextFormField (#108629)

This commit is contained in:
Greg Spencer 2022-07-29 10:13:09 -07:00 committed by GitHub
parent db3b1411b7
commit 5532775b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -125,6 +125,7 @@ class TextFormField extends FormField<String> {
int? maxLength,
ValueChanged<String>? onChanged,
GestureTapCallback? onTap,
TapRegionCallback? onTapOutside,
VoidCallback? onEditingComplete,
ValueChanged<String>? onFieldSubmitted,
super.onSaved,
@ -216,6 +217,7 @@ class TextFormField extends FormField<String> {
maxLength: maxLength,
onChanged: onChangedHandler,
onTap: onTap,
onTapOutside: onTapOutside,
onEditingComplete: onEditingComplete,
onSubmitted: onFieldSubmitted,
inputFormatters: inputFormatters,

View File

@ -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: <Widget>[
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(