import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class FlutterWebviewPlugin { static bool _init = false; static StreamController _onDestroy = new StreamController.broadcast(); static Stream get onDestroy => _onDestroy.stream; static const MethodChannel _channel = const MethodChannel('flutter_webview_plugin'); static Future launch(String url, {bool withJavascript: true, bool clearCache: false, bool clearCookies: false}) => _channel.invokeMethod('launch', { "url": url, "withJavascript": withJavascript, "clearCache": clearCache, "clearCookies": clearCookies }); static Future close() => _channel.invokeMethod("close"); static init() { if (!_init) { _init = true; _channel.setMethodCallHandler(_handleMessages); } } static Future _handleMessages(MethodCall call) async { if (call.method == "onDestroy") { _onDestroy.add(null); } } }