onTapOutside property Null safety
Called for each tap that occurs outside of theTextFieldTapRegion group when the text field is focused.
If this is null, FocusNode.unfocus will be called on the focusNode for this text field when a PointerDownEvent is received on another part of the UI. However, it will not unfocus as a result of mobile application touch events (which does not include mouse clicks), to conform with the platform conventions. To change this behavior, a callback may be set here that operates differently from the default.
When adding additional controls to a text field (for example, a spinner, a button that copies the selected text, or modifies formatting), it is helpful if tapping on that control doesn't unfocus the text field. In order for an external widget to be considered as part of the text field for the purposes of tapping "outside" of the field, wrap the control in a TextFieldTapRegion.
The PointerDownEvent passed to the function is the event that caused the notification. It is possible that the event may occur outside of the immediate bounding box defined by the text field, although it will be within the bounding box of a TextFieldTapRegion member.
TextFieldTapRegion
to wrap a set of
"spinner" buttons that increment and decrement a value in the TextField
without causing the text field to lose keyboard focus.
This example includes a generic SpinnerField<T>
class that you can copy
into your own project and customize.
flutter create --sample=widgets.EditableText.onTapOutside.1 mysample
See also:
- TapRegion for how the region group is determined.
Implementation
final TapRegionCallback? onTapOutside;