conditionalToggle static method

KeyBindings conditionalToggle({
  1. required bool isEnabled(),
  2. required void onToggle(),
  3. String hintLabel = 'Space',
  4. String hintDescription = 'select',
})

Creates conditional toggle binding (Space only when isEnabled is true).

Useful for multi-select modes where toggle is only available when multi-select is enabled or when the underlying data needs validation before allowing a toggle.

Implementation

static KeyBindings conditionalToggle({
  required bool Function() isEnabled,
  required void Function() onToggle,
  String hintLabel = 'Space',
  String hintDescription = 'select',
}) {
  return KeyBindings([
    KeyBinding.single(
      KeyEventType.space,
      (event) {
        if (!isEnabled()) return KeyActionResult.ignored;
        onToggle();
        return KeyActionResult.handled;
      },
      hintLabel: hintLabel,
      hintDescription: hintDescription,
    ),
  ]);
}