directionalNavigation static method

KeyBindings directionalNavigation({
  1. void onUp()?,
  2. void onDown()?,
  3. void onLeft()?,
  4. void onRight()?,
  5. String hintLabel = '↑/↓/←/→',
  6. String hintDescription = 'navigate',
})

Creates all-direction navigation bindings (↑/↓/←/→).

Implementation

static KeyBindings directionalNavigation({
  void Function()? onUp,
  void Function()? onDown,
  void Function()? onLeft,
  void Function()? onRight,
  String hintLabel = '↑/↓/←/→',
  String hintDescription = 'navigate',
}) {
  final bindings = <KeyBinding>[];

  if (onUp != null) {
    bindings.add(KeyBinding.single(
      KeyEventType.arrowUp,
      (event) {
        onUp();
        return KeyActionResult.handled;
      },
    ));
  }

  if (onDown != null) {
    bindings.add(KeyBinding.single(
      KeyEventType.arrowDown,
      (event) {
        onDown();
        return KeyActionResult.handled;
      },
    ));
  }

  if (onLeft != null) {
    bindings.add(KeyBinding.single(
      KeyEventType.arrowLeft,
      (event) {
        onLeft();
        return KeyActionResult.handled;
      },
    ));
  }

  if (onRight != null) {
    bindings.add(KeyBinding.single(
      KeyEventType.arrowRight,
      (event) {
        onRight();
        return KeyActionResult.handled;
      },
      hintLabel: hintLabel,
      hintDescription: hintDescription,
    ));
  }

  return KeyBindings(bindings);
}