Giter VIP home page Giter VIP logo

flutter_windows_webview's Introduction

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

flutter_windows_webview's People

Contributors

miaomint avatar wgh136 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.