numbers static method

KeyBindings numbers({
  1. required void onNumber(
    1. int number
    ),
  2. int max = 9,
  3. bool includeZero = false,
  4. String? hintLabel,
  5. String? hintDescription,
})

Creates number key bindings (default 1-9, optionally 0).

Handy for quick-select lists where pressing 3 should highlight/confirm the third entry. Set max to limit accepted digits and includeZero to keep 0 as a valid shortcut.

Implementation

static KeyBindings numbers({
  required void Function(int number) onNumber,
  int max = 9,
  bool includeZero = false,
  String? hintLabel,
  String? hintDescription,
}) {
  return KeyBindings([
    KeyBinding.char(
      (char) {
        if (!RegExp(r'^[0-9]$').hasMatch(char)) return false;
        final n = int.parse(char);
        if (n == 0 && !includeZero) return false;
        if (n > max) return false;
        return true;
      },
      (event) {
        final n = int.parse(event.char!);
        onNumber(n);
        return KeyActionResult.handled;
      },
      hintLabel: hintLabel ?? (includeZero ? '0–$max' : '1–$max'),
      hintDescription: hintDescription ?? 'set value',
    ),
  ]);
}