conditionalTextInput static method

KeyBindings conditionalTextInput({
  1. required TextInputBuffer buffer,
  2. required bool isEnabled(),
  3. 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;
      },
    ),
  ]);
}