admin管理员组

文章数量:1292995

Background

I am developing a Windows application. Due to text rendering issues (not-clear text issues) on Windows with skia, I am implementing my chat room area by embedding InAppWebView. So my purpose of putting InAppWebView into my widget tree is to work around the text rendering problems.

How WebView is Used

The area wrapped by the Container with the red border in the image below is the InAppWebView widget.

Actual Behavior (Problem)

If I press the Alt + F4 shortcut key while the WebView area is focused, the WebView terminates. When the WebView is terminated in this way, no event is triggered. I cannot detect that the WebView has been terminated.

Expected Behavior

Both of the followings. Or either one.

  1. If I press the Alt + F4, the entire app should be terminated, not only the WebView.
  2. It should be possible to detect when the WebView is terminated.

Steps with code example to reproduce

  1. Windows environment desktop app
  2. Mouse click on the WebView area to focus the WebView area
  3. Press ALT + F4

Flutter version

v3.27.4

Operating System, Device-specific and/or Tool

flutter doctor

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.27.4, on Microsoft Windows [Version 10.0.19045.3803]) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.13.0) [√] Android Studio (version 2023.1) [√] VS Code (version 1.97.1) [√] Connected device (3 available) [√] Network resources

Plugin version

v6.1.5

Troubleshooting Attempts

  1. (JavaScript) onbeforeunload

    This failed because the termination occurs first at the OS level before the JavaScript event can be triggered.

  2. (InAppWebView) onCloseWindow

    This does not work because the WebView is terminated before the WindowCloseRequest event is detected.

  3. (Flutter) Wrapping InAppWebView with KeyboardListener

    When the WebView is focused, no event that KeyboardListener can detect is triggered even if a key is pressed.

  4. (Flutter) Prevent Being Focused with IgnorePointer My chat system needs a clickable message(e.g. download). So there are restrictions to use it.

  5. Reasearch on Other Libraries

    1. desktop_webview_window

    This library can detect the close event. However, it cannot be embedded within the screen as a Flutter widget. It operates in a separate window. I believe it can detect the close event because it operates in a separate window.

    The key of this library's close event listener seems to be implementing MessageHandler in desktop_webview_window/windows/webview_window. I believe the implementation above could be a big hint to solving the issue at hand.

    Since it appears in a separate window, it cannot be used as an alternative to InAppWebView.

    1. webview_win_floating

    This library does not implement texture. So always the WebView floating. Perhaps because of this, there is no special reaction in the WebView even if Alt + F4 is pressed. Naturally, the entire Flutter app is terminated after Alt + F4 is pressed.

    However, due to an absence of texture, there are too many restrictions to use it.

    1. the others

    the other libraries are in the same situation as flutter_inappwebview (either they cannot detect a close event with their own event listener such as onCloseWindow of InAppWebView or they don't have any event listeners related with termination).

本文标签: