conditionalTextInput static method
KeyBindings
conditionalTextInput({
- required TextInputBuffer buffer,
- required bool isEnabled(),
- void onInput()?,
Creates conditional text input bindings (only active when condition is true).
Useful for search fields that can be toggled on/off.
Implementation
static KeyBindings conditionalTextInput({
required TextInputBuffer buffer,
required bool Function() isEnabled,
void Function()? onInput,
}) {
return KeyBindings([
KeyBinding(
keys: {
KeyEventType.char,
KeyEventType.backspace,
KeyEventType.arrowLeft,
KeyEventType.arrowRight,
},
action: (event) {
if (!isEnabled()) return KeyActionResult.ignored;
if (buffer.handleKey(event)) {
onInput?.call();
return KeyActionResult.handled;
}
return KeyActionResult.ignored;
},
),
]);
}