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.
- If I press the Alt + F4, the entire app should be terminated, not only the WebView.
- It should be possible to detect when the WebView is terminated.
Steps with code example to reproduce
- Windows environment desktop app
- Mouse click on the WebView area to focus the WebView area
- 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
(JavaScript)
onbeforeunload
This failed because the termination occurs first at the OS level before the JavaScript event can be triggered.
(InAppWebView)
onCloseWindow
This does not work because the WebView is terminated before the
WindowCloseRequest
event is detected.(Flutter) Wrapping InAppWebView with
KeyboardListener
When the WebView is focused, no event that
KeyboardListener
can detect is triggered even if a key is pressed.(Flutter) Prevent Being Focused with
IgnorePointer
My chat system needs a clickable message(e.g. download). So there are restrictions to use it.Reasearch on Other Libraries
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
indesktop_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
.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.
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 asonCloseWindow
ofInAppWebView
or they don't have any event listeners related with termination).
本文标签:
版权声明:本文标题:flutter - Inability to Detect Close Event When WebView is Terminated at the OS Level On Windows. How to solve it? - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741564426a2385639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论