bind static method
Binds the callback
to keybinding
in the Keybinder.
callback
can be provided as a Function without a parameter,
as a ValueChanged<bool>
callback (a function with a single
boolean parameter,) or as a KeybindingEvent, which has a
Keybinding parameter and a boolean parameter:
void Function(Keybinding keybinding, bool pressed)
.
Implementation
static void bind(Keybinding keybinding, Function callback) {
assert(
callback is VoidCallback ||
callback is ValueChanged<bool> ||
callback is KeybindingEvent,
'[callback] must be a [VoidCallback], `ValueChanged<bool>`, '
'or a [KeybindingEvent].');
// Initialize the [HardwareKeyboard] listener, if it hasn't already been.
if (_hardwareKeyboard == null) _init();
// Add the callback to the [_keybindings] map.
if (_keybindings.containsKey(keybinding)) {
_keybindings[keybinding]!.add(callback);
} else {
_keybindings.addAll({
keybinding: [callback],
});
}
}