onTapOutside property
Called for each tap down that occurs outside of the TextFieldTapRegion group when the text field is focused.
If this is null, EditableTextTapOutsideIntent will be invoked. In the default implementation, 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 or EditableTextTapOutsideIntent may be overridden.
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.
To create a local project with this code sample, run:
flutter create --sample=widgets.EditableText.onTapOutside.1 mysample
See also:
- TapRegion for how the region group is determined.
- onTapUpOutside which is called for each tap up.
- EditableTextTapOutsideIntent for the intent that is invoked if this is null.
Implementation
final TapRegionCallback? onTapOutside;