wgh136 / flutter_windows_webview

A plugin that provides a webview interface for Flutter on Windows.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

flutter_windows_webview

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.

Getting Started

Check if webview is available

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());
}

Create webview

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.

Run script

Before running the script, make sure the webview is running.

use script

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\")");
}

Sending message from the webview

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

listen title's change

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

cookies

Get cookie

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
}

Navigate

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");
}

User-Agent

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");
}

Close

import 'package:flutter_windows_webview/flutter_windows_webview.dart';

void test(){
  var webview = FlutterWindowsWebview();
  webview.launchWebview("https://www.google.com");
  webview.close();
}

About

A plugin that provides a webview interface for Flutter on Windows.

License:Other


Languages

Language:C++ 65.7%Language:C 32.8%Language:CMake 1.1%Language:Dart 0.4%Language:Batchfile 0.0%