isSpaceKey function
Determines if the space key was pressed in a KeyboardEvent.
Use this utility because keyCode
is deprecated in Firefox (and doesn't
work for <space>) and key
is not yet implemented in Chrome.
Implementation
bool isSpaceKey(KeyboardEvent event) {
// NB: keyCode does not work on Firefox, returning `0` for the space key.
return event.keyCode != 0 ? event.keyCode == KeyCode.SPACE : event.key == ' ';
}