Coder Social home page Coder Social logo

andrewlee1228 / flutter_jsbridge_plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lazyfatcat/flutter_jsbridge_plugin

0.0 1.0 0.0 127 KB

License: BSD 3-Clause "New" or "Revised" License

JavaScript 6.75% Ruby 6.87% Objective-C 4.94% Java 10.88% Dart 66.89% HTML 3.66%

flutter_jsbridge_plugin's Introduction

Add JsBridge Plugin to the WebView

A Flutter plugin that provides a JsBridge on WebView widget.

This plugin must introduce webview_flutter

Usage

Add flutter_jsbridge_plugin as a dependency in your pubspec.yaml file.

dependencies:
  flutter_jsbridge_plugin:
    git:
      url: git://github.com/xiaomaxuetu/flutter_jsbridge_plugin
      ref: master

Init JsBridge and register handler

...
final JsBridge _jsBridge = JsBridge();
...
WebView(
    initialUrl: "https://www.baidu.com?timeStamp=${new DateTime.now().millisecondsSinceEpoch}",
    javascriptMode: JavascriptMode.unrestricted,
    onWebViewCreated: (WebViewController webViewController) async {
        _jsBridge.loadJs(webViewController);
        _controller.complete(webViewController);
        _jsBridge.registerHandler("getToken", onCallBack: (data, func) {
            // return token to js
            func({"token": "token"});
        });
        _jsBridge.registerHandler("IAPpayment", onCallBack: (data, func) {
            print("js call flutter iap");
        });
        _jsBridge.registerHandler("back", onCallBack: (data, func) {
            print("js call flutter back");
        });
    },
    navigationDelegate: (NavigationRequest request) {
        if (_jsBridge.handlerUrl(request.url)) {
            return NavigationDecision.navigate;
        }
        return NavigationDecision.prevent;
    },
    onPageStarted: (url) {
        _jsBridge.init();
    },
))

JS Usage

js file

flutter_jsbridge_plugin's People

Contributors

andrewlee1228 avatar lazyfatcat avatar xiaomaxuetu avatar

Watchers

 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.