Reputation: 93
I want to use the 'escape' key in Flutter web to change the widget. The issue that I have is, when in fullscreen my RawKeyboardListener doesn't detect the escape key pressed, unlike when not in fullscreen. I was wondering how to rectify this:
Here is my fullscreen function:
void goFullScreen() {
document.documentElement!.requestFullscreen();
}
Here is my RawKeyboardListener:
RawKeyboardListener(
autofocus: true,
focusNode: FocusNode(),
onKey: (event){
if (event.isKeyPressed(LogicalKeyboardKey.exit)) {
print('escape pressed');
}
},
Upvotes: 2
Views: 1009
Reputation: 686
Had a similar problem with this as well, what helped is listening to the document onFullscreenchange events:
document.documentElement?.onFullscreenChange.listen((event) {
if (document.fullscreenElement==null) {
print("do something");
}
});
It's in the documentation for the fullscreenElement on the mozilla website. When the full screen is existed the fullscreenElement variable is set to null.
Upvotes: 1