Skip to content

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

License

Notifications You must be signed in to change notification settings

wgh136/flutter_windows_webview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published