gridNavigation static method
Creates 2D grid navigation bindings with custom move functions.
Used for grid-based selection (GridSelect, ChoiceMap) where navigation wraps around edges and needs custom logic.
Implementation
static KeyBindings gridNavigation({
required void Function() onUp,
required void Function() onDown,
required void Function() onLeft,
required void Function() onRight,
String hintLabel = '↑/↓/←/→',
String hintDescription = 'navigate',
}) {
return KeyBindings([
KeyBinding.single(KeyEventType.arrowUp, (event) {
onUp();
return KeyActionResult.handled;
}),
KeyBinding.single(KeyEventType.arrowDown, (event) {
onDown();
return KeyActionResult.handled;
}),
KeyBinding.single(KeyEventType.arrowLeft, (event) {
onLeft();
return KeyActionResult.handled;
}),
KeyBinding.single(
KeyEventType.arrowRight,
(event) {
onRight();
return KeyActionResult.handled;
},
hintLabel: hintLabel,
hintDescription: hintDescription,
),
]);
}