build method
Build the widget.
Implementation
@override
Widget build(final BuildContext context) {
final keyboard = HardwareKeyboard.instance;
return InheritedGameShortcuts(
shortcuts: shortcuts,
child: Builder(
builder: (final innerContext) => Focus(
autofocus: autofocus,
onKeyEvent: (final node, final event) {
if (event is KeyRepeatEvent) {
return KeyEventResult.ignored;
}
for (final shortcut in shortcuts) {
if (shortcut.shortcut.key == event.physicalKey &&
shortcut.controlKey == keyboard.isControlPressed &&
shortcut.metaKey == keyboard.isMetaPressed &&
shortcut.altKey == keyboard.isAltPressed &&
shortcut.shiftKey == keyboard.isShiftPressed) {
if (event is KeyDownEvent) {
shortcut.onStart?.call(innerContext);
} else {
shortcut.onStop?.call(innerContext);
}
return KeyEventResult.handled;
}
}
return KeyEventResult.ignored;
},
focusNode: focusNode,
canRequestFocus: canRequestFocus,
child: child,
),
),
);
}