gridSelection static method

KeyBindings gridSelection({
  1. required void onUp(),
  2. required void onDown(),
  3. required void onLeft(),
  4. required void onRight(),
  5. void onToggle()?,
  6. bool showToggleHint = false,
  7. KeyActionResult onConfirm()?,
  8. void onCancel()?,
})

Creates 2D grid selection bindings (navigation + optional toggle + confirm + cancel).

Useful for multi-column selectors where arrow keys move the cursor and an optional space-bar toggle is exposed for selecting cells inline.

Implementation

static KeyBindings gridSelection({
  required void Function() onUp,
  required void Function() onDown,
  required void Function() onLeft,
  required void Function() onRight,
  void Function()? onToggle,
  bool showToggleHint = false,
  KeyActionResult Function()? onConfirm,
  void Function()? onCancel,
}) {
  var bindings = gridNavigation(
    onUp: onUp,
    onDown: onDown,
    onLeft: onLeft,
    onRight: onRight,
  );

  if (onToggle != null) {
    bindings = bindings +
        KeyBindings([
          KeyBinding.single(
            KeyEventType.space,
            (event) {
              onToggle();
              return KeyActionResult.handled;
            },
            hintLabel: showToggleHint ? 'Space' : null,
            hintDescription: showToggleHint ? 'toggle selection' : null,
          ),
        ]);
  }

  return bindings +
      confirm(onConfirm: onConfirm) +
      cancel(onCancel: onCancel);
}