togglePrompt static method

KeyBindings togglePrompt({
  1. required void onToggle(),
  2. KeyActionResult onConfirm()?,
  3. void onCancel()?,
  4. String toggleHint = 'toggle',
})

Standard toggle bindings: arrows toggle + space toggle + confirm + cancel.

Implementation

static KeyBindings togglePrompt({
  required void Function() onToggle,
  KeyActionResult Function()? onConfirm,
  void Function()? onCancel,
  String toggleHint = 'toggle',
}) {
  return KeyBindings([
        // All arrow keys toggle
        KeyBinding.multi(
          {
            KeyEventType.arrowLeft,
            KeyEventType.arrowRight,
            KeyEventType.arrowUp,
            KeyEventType.arrowDown,
          },
          (event) {
            onToggle();
            return KeyActionResult.handled;
          },
          hintLabel: '←/→',
          hintDescription: toggleHint,
        ),
        // Space also toggles
        KeyBinding.single(
          KeyEventType.space,
          (event) {
            onToggle();
            return KeyActionResult.handled;
          },
        ),
      ]) +
      confirm(onConfirm: onConfirm) +
      cancel(onCancel: onCancel);
}