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