|
|
@@ -31,20 +31,21 @@ class FlutterWebviewPlugin {
|
|
|
|
|
|
Future<Null> _handleMessages(MethodCall call) async {
|
|
|
switch (call.method) {
|
|
|
- case "onDestroy":
|
|
|
+ case 'onDestroy':
|
|
|
_onDestroy.add(null);
|
|
|
break;
|
|
|
- case "onUrlChanged":
|
|
|
- _onUrlChanged.add(call.arguments["url"]);
|
|
|
+ case 'onUrlChanged':
|
|
|
+ _onUrlChanged.add(call.arguments['url']);
|
|
|
break;
|
|
|
- case "onState":
|
|
|
+ case 'onState':
|
|
|
_onStateChanged.add(
|
|
|
new WebViewStateChanged.fromMap(
|
|
|
new Map<String, dynamic>.from(call.arguments)),
|
|
|
);
|
|
|
break;
|
|
|
- case "onHttpError":
|
|
|
- _onHttpError.add(WebViewHttpError(call.arguments['code'], call.arguments['url']));
|
|
|
+ case 'onHttpError':
|
|
|
+ _onHttpError.add(
|
|
|
+ WebViewHttpError(call.arguments['code'], call.arguments['url']));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -93,30 +94,30 @@ class FlutterWebviewPlugin {
|
|
|
bool withLocalStorage,
|
|
|
bool withLocalUrl,
|
|
|
bool scrollBar}) async {
|
|
|
- Map<String, dynamic> args = {
|
|
|
- "url": url,
|
|
|
- "withJavascript": withJavascript ?? true,
|
|
|
- "clearCache": clearCache ?? false,
|
|
|
- "hidden": hidden ?? false,
|
|
|
- "clearCookies": clearCookies ?? false,
|
|
|
- "enableAppScheme": enableAppScheme ?? true,
|
|
|
- "userAgent": userAgent,
|
|
|
- "withZoom": withZoom ?? false,
|
|
|
- "withLocalStorage": withLocalStorage ?? true,
|
|
|
- "withLocalUrl": withLocalUrl ?? false,
|
|
|
- "scrollBar": scrollBar ?? true
|
|
|
+ final args = <String, dynamic>{
|
|
|
+ 'url': url,
|
|
|
+ 'withJavascript': withJavascript ?? true,
|
|
|
+ 'clearCache': clearCache ?? false,
|
|
|
+ 'hidden': hidden ?? false,
|
|
|
+ 'clearCookies': clearCookies ?? false,
|
|
|
+ 'enableAppScheme': enableAppScheme ?? true,
|
|
|
+ 'userAgent': userAgent,
|
|
|
+ 'withZoom': withZoom ?? false,
|
|
|
+ 'withLocalStorage': withLocalStorage ?? true,
|
|
|
+ 'withLocalUrl': withLocalUrl ?? false,
|
|
|
+ 'scrollBar': scrollBar ?? true
|
|
|
};
|
|
|
|
|
|
if (headers != null) {
|
|
|
- args["headers"] = headers;
|
|
|
+ args['headers'] = headers;
|
|
|
}
|
|
|
|
|
|
if (rect != null) {
|
|
|
- args["rect"] = {
|
|
|
- "left": rect.left,
|
|
|
- "top": rect.top,
|
|
|
- "width": rect.width,
|
|
|
- "height": rect.height
|
|
|
+ args['rect'] = {
|
|
|
+ 'left': rect.left,
|
|
|
+ 'top': rect.top,
|
|
|
+ 'width': rect.width,
|
|
|
+ 'height': rect.height
|
|
|
};
|
|
|
}
|
|
|
await _channel.invokeMethod('launch', args);
|
|
|
@@ -124,47 +125,47 @@ class FlutterWebviewPlugin {
|
|
|
|
|
|
/// Execute Javascript inside webview
|
|
|
Future<String> evalJavascript(String code) async {
|
|
|
- final res = await _channel.invokeMethod('eval', {"code": code});
|
|
|
+ final res = await _channel.invokeMethod('eval', {'code': code});
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
/// Close the Webview
|
|
|
/// Will trigger the [onDestroy] event
|
|
|
- Future close() => _channel.invokeMethod("close");
|
|
|
+ Future close() => _channel.invokeMethod('close');
|
|
|
|
|
|
/// Reloads the WebView.
|
|
|
/// This is only available on Android for now.
|
|
|
- Future reload() => _channel.invokeMethod("reload");
|
|
|
+ Future reload() => _channel.invokeMethod('reload');
|
|
|
|
|
|
/// Navigates back on the Webview.
|
|
|
/// This is only available on Android for now.
|
|
|
- Future goBack() => _channel.invokeMethod("back");
|
|
|
+ Future goBack() => _channel.invokeMethod('back');
|
|
|
|
|
|
/// Navigates forward on the Webview.
|
|
|
/// This is only available on Android for now.
|
|
|
- Future goForward() => _channel.invokeMethod("forward");
|
|
|
+ Future goForward() => _channel.invokeMethod('forward');
|
|
|
|
|
|
// Hides the webview
|
|
|
- Future hide() => _channel.invokeMethod("hide");
|
|
|
+ Future hide() => _channel.invokeMethod('hide');
|
|
|
|
|
|
// Shows the webview
|
|
|
- Future show() => _channel.invokeMethod("show");
|
|
|
+ Future show() => _channel.invokeMethod('show');
|
|
|
|
|
|
// Reload webview with a new url
|
|
|
Future reloadUrl(String url) async {
|
|
|
- Map<String, dynamic> args = {
|
|
|
- "url": url
|
|
|
- };
|
|
|
- await _channel.invokeMethod("reloadUrl", args);
|
|
|
+ final args = <String, String>{'url': url};
|
|
|
+ await _channel.invokeMethod('reloadUrl', args);
|
|
|
}
|
|
|
|
|
|
/// adds the plugin as ActivityResultListener
|
|
|
/// Only needed and used on Android
|
|
|
- Future registerAcitivityResultListener() => _channel.invokeMethod("registerAcitivityResultListener");
|
|
|
+ Future registerAcitivityResultListener() =>
|
|
|
+ _channel.invokeMethod('registerAcitivityResultListener');
|
|
|
|
|
|
/// removes the plugin as ActivityResultListener
|
|
|
/// Only needed and used on Android
|
|
|
- Future removeAcitivityResultListener() => _channel.invokeMethod("removeAcitivityResultListener");
|
|
|
+ Future removeAcitivityResultListener() =>
|
|
|
+ _channel.invokeMethod('removeAcitivityResultListener');
|
|
|
|
|
|
/// Close all Streams
|
|
|
void dispose() {
|
|
|
@@ -176,12 +177,12 @@ class FlutterWebviewPlugin {
|
|
|
}
|
|
|
|
|
|
Future<Map<String, String>> getCookies() async {
|
|
|
- final cookiesString = await evalJavascript("document.cookie");
|
|
|
+ final cookiesString = await evalJavascript('document.cookie');
|
|
|
final cookies = <String, String>{};
|
|
|
|
|
|
if (cookiesString?.isNotEmpty == true) {
|
|
|
- cookiesString.split(";").forEach((String cookie) {
|
|
|
- final splited = cookie.split("=");
|
|
|
+ cookiesString.split(';').forEach((String cookie) {
|
|
|
+ final splited = cookie.split('=');
|
|
|
cookies[splited[0]] = splited[1];
|
|
|
});
|
|
|
}
|
|
|
@@ -192,11 +193,11 @@ class FlutterWebviewPlugin {
|
|
|
/// resize webview
|
|
|
Future<Null> resize(Rect rect) async {
|
|
|
final args = {};
|
|
|
- args["rect"] = {
|
|
|
- "left": rect.left,
|
|
|
- "top": rect.top,
|
|
|
- "width": rect.width,
|
|
|
- "height": rect.height
|
|
|
+ args['rect'] = {
|
|
|
+ 'left': rect.left,
|
|
|
+ 'top': rect.top,
|
|
|
+ 'width': rect.width,
|
|
|
+ 'height': rect.height
|
|
|
};
|
|
|
await _channel.invokeMethod('resize', args);
|
|
|
}
|
|
|
@@ -211,18 +212,18 @@ class WebViewStateChanged {
|
|
|
|
|
|
factory WebViewStateChanged.fromMap(Map<String, dynamic> map) {
|
|
|
WebViewState t;
|
|
|
- switch (map["type"]) {
|
|
|
- case "shouldStart":
|
|
|
+ switch (map['type']) {
|
|
|
+ case 'shouldStart':
|
|
|
t = WebViewState.shouldStart;
|
|
|
break;
|
|
|
- case "startLoad":
|
|
|
+ case 'startLoad':
|
|
|
t = WebViewState.startLoad;
|
|
|
break;
|
|
|
- case "finishLoad":
|
|
|
+ case 'finishLoad':
|
|
|
t = WebViewState.finishLoad;
|
|
|
break;
|
|
|
}
|
|
|
- return new WebViewStateChanged(t, map["url"], map["navigationType"]);
|
|
|
+ return new WebViewStateChanged(t, map['url'], map['navigationType']);
|
|
|
}
|
|
|
}
|
|
|
|