Skip to content

Commit 30a86b5

Browse files
committed
feat: add onTapOutside to FormBuilderTextField
1 parent edcebe5 commit 30a86b5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/src/fields/form_builder_text_field.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ class FormBuilderTextField extends FormBuilderFieldDecoration<String> {
203203
/// {@endtemplate}
204204
final GestureTapCallback? onTap;
205205

206+
/// {@template flutter.material.textfield.onTapOutside}
207+
/// A callback to be invoked when a tap is detected outside of this TapRegion
208+
/// and any other region with the same groupId, if any.
209+
///
210+
/// The PointerDownEvent passed to the function is the event that caused the
211+
/// notification. If this region is part of a group (i.e. groupId is set),
212+
/// then it's possible that the event may be outside of this immediate region,
213+
/// although it will be within the region of one of the group members.
214+
/// {@endtemplate}
215+
final TapRegionCallback? onTapOutside;
216+
206217
/// The cursor for a mouse pointer when it enters or is hovering over the
207218
/// widget.
208219
///
@@ -322,6 +333,7 @@ class FormBuilderTextField extends FormBuilderFieldDecoration<String> {
322333
this.minLines,
323334
this.showCursor,
324335
this.onTap,
336+
this.onTapOutside,
325337
this.enableSuggestions = false,
326338
this.textAlignVertical,
327339
this.dragStartBehavior = DragStartBehavior.start,
@@ -381,6 +393,7 @@ class FormBuilderTextField extends FormBuilderFieldDecoration<String> {
381393
expands: expands,
382394
maxLength: maxLength,
383395
onTap: onTap,
396+
onTapOutside: onTapOutside,
384397
onEditingComplete: onEditingComplete,
385398
onSubmitted: onSubmitted,
386399
inputFormatters: inputFormatters,

test/form_builder_text_field_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/material.dart';
12
import 'package:flutter_form_builder/flutter_form_builder.dart';
23
import 'package:flutter_test/flutter_test.dart';
34

@@ -43,6 +44,11 @@ void main() {
4344
initialValueOnForm: 'ok',
4445
),
4546
);
47+
48+
testWidgets(
49+
'FormBuilderTextField triggers onTapOutside',
50+
(tester) => _testFormBuilderTextFieldOnTapOutsideCallback(tester),
51+
);
4652
}
4753

4854
Future<void> _testFormBuilderTextFieldWithInitialValue(
@@ -75,3 +81,20 @@ Future<void> _testFormBuilderTextFieldWithInitialValue(
7581

7682
expect(changedCount, 1);
7783
}
84+
85+
Future<void> _testFormBuilderTextFieldOnTapOutsideCallback(
86+
WidgetTester tester) async {
87+
const textFieldName = 'Hello 🪐';
88+
bool triggered = false;
89+
90+
var testWidget = FormBuilderTextField(
91+
name: textFieldName,
92+
onTapOutside: (event) => triggered = true,
93+
);
94+
await tester.pumpWidget(buildTestableFieldWidget(
95+
testWidget,
96+
));
97+
final textField = tester.firstWidget(find.byType(TextField)) as TextField;
98+
textField.onTapOutside?.call(const PointerDownEvent());
99+
expect(triggered, true);
100+
}

0 commit comments

Comments
 (0)