DB Cooper
DB Cooper

Reputation: 93

Flutter Web RawKeyboardListener 'escape' not working in Fullscreen

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

Answers (1)

Abdelghani Bekka
Abdelghani Bekka

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

Related Questions