textInput static method
KeyBindings
textInput({
- required TextInputBuffer buffer(),
- bool isEnabled()?,
- void onInput()?,
- void onTextChanged()?,
Text editing bindings for a fixed or dynamically focused buffer.
Recognized editing keys are consumed even when nothing changes (for
example, backspace at the start or typing at maxLength). onInput runs
only when text or cursor state changes; onTextChanged runs only for text
changes. Disabled bindings ignore events.
Implementation
static KeyBindings textInput({
required TextInputBuffer Function() buffer,
bool Function()? isEnabled,
void Function()? onInput,
void Function()? onTextChanged,
}) {
return KeyBindings([
KeyBinding(
keys: {
KeyEventType.char,
KeyEventType.space,
KeyEventType.slash,
KeyEventType.backspace,
KeyEventType.arrowLeft,
KeyEventType.arrowRight,
},
action: (event) {
if (isEnabled != null && !isEnabled()) return KeyActionResult.ignored;
if (event.type == KeyEventType.char && event.printableText == null) {
return KeyActionResult.ignored;
}
final input = buffer();
final previousText = input.text;
if (input.handleKey(event)) onInput?.call();
if (input.text != previousText) onTextChanged?.call();
return KeyActionResult.handled;
},
),
]);
}