WebView for flutter

Base on webview_flutter, add some new features.

  • backgroundColor
  • onProgressChanged
  • shouldInterceptRequest: intercept request and load resource from local.
  • onScroll: listen webview scroll.

how to use

dependencies:
  iwebview_flutter: ^latest version
WebView(
      initialUrl: "https://www.google.com",
      javascriptMode: JavascriptMode.unrestricted,
      debuggingEnabled: true,
      onProgressChanged: (int p){//0-100
        setState(() {
          progress = p/100.0;
        });
      },
      onScroll(int x,int y){

      },
      backgroundColor: Colors.red,
      shouldInterceptRequest: (String url) async {//replace google logo
        var googleLogo = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_160x56dp.png";
        print("============url:$url");
        if (url == googleLogo) {
          ByteData data = await rootBundle.load("assets/baidu.png");
          Uint8List bytes = Uint8List.view(data.buffer);
          return Response("image/png", null, bytes);
        }
        return null;
      },
),

Libraries

platform_interface
webview_flutter

Dart

VM

dart:ffi
Foreign Function Interface for interoperability with the C programming language. [...]

Web

dart:html
HTML elements and other resources for web-based applications that need to interact with the browser and the DOM (Document Object Model). [...]
dart:js
Low-level support for interoperating with JavaScript. [...]
dart:js_util
Utility methods to efficiently manipulate typed JSInterop objects in cases where the name to call is not known at runtime. You should only use these methods when the same effect cannot be achieved with @JS annotations. These methods would be extension methods on JSObject if Dart supported extension methods.