This package is not complete, do not use it in production.
A plugin that provides a webview interface for Flutter on Windows.
Currently, this plugin only provides some basic functionality.
Webview is not supported on all versions of Windows. Use the following code to check if it is available.
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
print(FlutterWindowsWebview.isAvailable());
}
Run the following code;
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
FlutterWindowsWebview().launchWebview("https://www.google.com");
}
Then the webview window will be created.
Before running the script, make sure the webview is running.
The following code shows how to run a script:
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
var webview = FlutterWindowsWebview();
webview.launchWebview("https://www.google.com");
webview.runScript("alert(\"Hello World\")");
}
You can send a message from the webview:
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
var webview = FlutterWindowsWebview();
webview.launchWebview("https://www.google.com");
webview.runScript("window.chrome.webview.postMessage(\"Hello World\")");
}
If you want to receive these messages, you need to provide a messageReceiver when creating the webview:
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
FlutterWindowsWebview().launchWebview("https://www.google.com", WebviewOptions(messageReceiver: (message) => print(message)));
}
You need to provide an onTitleChange
callback when creating the webview:
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
FlutterWindowsWebview().launchWebview("https://www.google.com", WebviewOptions(onTitleChange: (message) => print(message)));
}
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
var webview = FlutterWindowsWebview();
webview.launchWebview("https://www.google.com");
var res = webview.getCookies("https://www.google.com");
print(res);v
}
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
var webview = FlutterWindowsWebview();
webview.launchWebview("https://www.google.com");
webview.navigateTo("https://www.bing.com");
}
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
var webview = FlutterWindowsWebview();
webview.setUA("Flutter Windows Webview");
webview.launchWebview("https://www.google.com");
}
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
void test(){
var webview = FlutterWindowsWebview();
webview.launchWebview("https://www.google.com");
webview.close();
}