'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');
        }
      },


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abdelghani Bekka