|
|
@@ -4,21 +4,28 @@ import 'package:flutter/material.dart';
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
|
class FlutterWebviewPlugin {
|
|
|
- static bool _init = false;
|
|
|
- static StreamController<Null> _onDestroy = new StreamController.broadcast();
|
|
|
- static Stream<Null> get onDestroy => _onDestroy.stream;
|
|
|
|
|
|
- static StreamController<Null> _onBackPressed =
|
|
|
- new StreamController.broadcast();
|
|
|
- static Stream<Null> get onBackPressed => _onDestroy.stream;
|
|
|
+ static FlutterWebviewPlugin _instance;
|
|
|
+ FlutterWebviewPlugin._() {
|
|
|
+ _init();
|
|
|
+ }
|
|
|
+ factory FlutterWebviewPlugin() => _instance ??= new FlutterWebviewPlugin._();
|
|
|
+
|
|
|
+
|
|
|
+ StreamController<Null> _onDestroy = new StreamController.broadcast();
|
|
|
+ Stream<Null> get onDestroy => _onDestroy.stream;
|
|
|
|
|
|
- static const MethodChannel _channel =
|
|
|
- const MethodChannel('flutter_webview_plugin');
|
|
|
+ StreamController<Null> _onBackPressed =
|
|
|
+ new StreamController.broadcast();
|
|
|
|
|
|
- static Future<Null> launch(String url,
|
|
|
- {bool withJavascript: true,
|
|
|
- bool clearCache: false,
|
|
|
- bool clearCookies: false}) =>
|
|
|
+ Stream<Null> get onBackPressed => _onDestroy.stream;
|
|
|
+
|
|
|
+ final MethodChannel _channel = const MethodChannel('flutter_webview_plugin');
|
|
|
+
|
|
|
+ Future<Null> launch(String url,
|
|
|
+ {bool withJavascript: true,
|
|
|
+ bool clearCache: false,
|
|
|
+ bool clearCookies: false}) =>
|
|
|
_channel.invokeMethod('launch', {
|
|
|
"url": url,
|
|
|
"withJavascript": withJavascript,
|
|
|
@@ -26,16 +33,13 @@ class FlutterWebviewPlugin {
|
|
|
"clearCookies": clearCookies
|
|
|
});
|
|
|
|
|
|
- static Future<Null> close() => _channel.invokeMethod("close");
|
|
|
+ Future<Null> close() => _channel.invokeMethod("close");
|
|
|
|
|
|
- static init() {
|
|
|
- if (!_init) {
|
|
|
- _init = true;
|
|
|
- _channel.setMethodCallHandler(_handleMessages);
|
|
|
- }
|
|
|
+ _init() {
|
|
|
+ _channel.setMethodCallHandler(_handleMessages);
|
|
|
}
|
|
|
|
|
|
- static Future<Null> _handleMessages(MethodCall call) async {
|
|
|
+ Future<Null> _handleMessages(MethodCall call) async {
|
|
|
switch (call.method) {
|
|
|
case "onDestroy":
|
|
|
_onDestroy.add(null);
|
|
|
@@ -45,4 +49,4 @@ class FlutterWebviewPlugin {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|