desktop_webview_window
Show a webview window on your flutter desktop application.
| Windows | ✅ | WebView2 SDK 1.0.4258.31 |
| Linux | ✅ | WebKitGTK-4.1 or WebKitGTK-4.0 |
| macOS | ✅ | WKWebview |
Getting Started
-
To enable the optional webview title-bar controls, modify your
mainmethod.import 'package:desktop_webview_window/desktop_webview_window.dart'; void main(List<String> args) async { WidgetsFlutterBinding.ensureInitialized(); // Add this your main method. // used to show a webview title bar. if (runWebViewTitleBarWidget(args)) { return; } runApp(MyApp()); } -
launch WebViewWindow
final webview = await WebviewWindow.create(); webview.launch("https://example.com");
linux requirement
In Ubuntu/Debian:
sudo apt-get install libwebkit2gtk-4.1-0 libwebkit2gtk-4.1-dev libsoup-3.0-0 libsoup-3.0-dev
In Fedora/RPM:
sudo dnf install webkit2gtk4.1 webkit2gtk4.1-devel libsoup3 libsoup3-devel
Windows
Requirement
The backend of desktop_webview_window on Windows is WebView2, which requires WebView2 Runtime installed.
WebView2 Runtime is ship in box with Windows11, but it may not installed on Windows10 devices. So you need consider how to distribute the runtime to your users.
See more: https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution
For convenience, you can use WebviewWindow.isWebviewAvailable() check whether the WebView2 is available.
Attention
The default user data folder of WebView2 is your_exe_file\WebView2, which is not a good place to store user data.
eg. if the application is installed in a read-only directory, the application will crash when WebView2 try to write data.
you can use WebviewWindow.create() to create a webview with a custom user data folder.
final webview = await WebviewWindow.create(
configuration: CreateConfiguration(
userDataFolderWindows: 'your_custom_user_data_folder',
),
);
Window and media options
CreateConfiguration(openHidden: true) creates a Windows WebView without
showing its window. Show it later with setWebviewWindowVisibility(true) or
bringToForeground(maximized: true).
CreateConfiguration(denyCameraAndMicrophone: true) denies camera and microphone
requests for that window without saving the denial in the shared profile.
This option requires WebView2 Runtime 111.0.1661.34 or later. Window creation
fails on older runtimes when this option is enabled. Both options default to
false.
Windows regression tests
Run from example/ on Windows with WebView2 Runtime installed:
$env:WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS = '--use-fake-device-for-media-stream'
flutter test integration_test/windows_webview_test.dart -d windows --timeout 5m
The tests use local pages, temporary profiles, and fake media devices. They do not require a physical camera or microphone.
The bundled Windows SDK headers, loader DLL, and import library come from Microsoft.Web.WebView2 SDK 1.0.4258.31.
License
see LICENSE