conditionalToggle static method
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,
),
]);
}