From f45273e2fe6e3a9a8d5308dc534f19b9bd3081ef Mon Sep 17 00:00:00 2001 From: Peter Thaler Date: Mon, 9 Jul 2018 08:13:13 +0200 Subject: [PATCH 1/2] added stop loading method and handling on android --- .../com/flutter_webview_plugin/FlutterWebviewPlugin.java | 9 +++++++++ .../java/com/flutter_webview_plugin/WebviewManager.java | 6 ++++++ lib/src/base.dart | 3 +++ 3 files changed, 18 insertions(+) diff --git a/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java b/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java index ee0714d3..b729c3bd 100644 --- a/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java +++ b/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java @@ -67,6 +67,9 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { break; case "reloadUrl": reloadUrl(call, result); + break; + case "stopLoading": + stopLoading(call, result); break; default: result.notImplemented(); @@ -124,6 +127,12 @@ private FrameLayout.LayoutParams buildLayoutParams(MethodCall call) { return params; } + private void stopLoading(MethodCall call, MethodChannel.Result result) { + if (webViewManager != null){ + webViewManager.stopLoading(call, result); + } + } + private void close(MethodCall call, MethodChannel.Result result) { if (webViewManager != null) { webViewManager.close(call, result); diff --git a/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java b/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java index a14e93ba..122cf1aa 100644 --- a/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java +++ b/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java @@ -279,4 +279,10 @@ void show(MethodCall call, MethodChannel.Result result) { webView.setVisibility(View.VISIBLE); } } + + void stopLoading(MethodCall call, MethodChannel.Result result){ + if (webView != null){ + webView.stopLoading(); + } + } } diff --git a/lib/src/base.dart b/lib/src/base.dart index 5568af74..7ab981bd 100644 --- a/lib/src/base.dart +++ b/lib/src/base.dart @@ -146,6 +146,9 @@ class FlutterWebviewPlugin { await _channel.invokeMethod("reloadUrl", args); } + // Stops current loading process + Future stopLoading() => _channel.invokeMethod("stopLoading"); + /// adds the plugin as ActivityResultListener /// Only needed and used on Android Future registerAcitivityResultListener() => _channel.invokeMethod("registerAcitivityResultListener"); From 88285fb61ca93c9068dbff53bd6d2472577ee0e2 Mon Sep 17 00:00:00 2001 From: Peter Thaler Date: Mon, 9 Jul 2018 10:52:34 +0200 Subject: [PATCH 2/2] added stopLoading call handling on iOS --- ios/Classes/FlutterWebviewPlugin.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ios/Classes/FlutterWebviewPlugin.m b/ios/Classes/FlutterWebviewPlugin.m index 0c9370aa..97ba0c0b 100644 --- a/ios/Classes/FlutterWebviewPlugin.m +++ b/ios/Classes/FlutterWebviewPlugin.m @@ -55,6 +55,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { } else if ([@"hide" isEqualToString:call.method]) { [self hide]; result(nil); + } else if ([@"stopLoading" isEqualToString:call.method]) { + [self stopLoading]; + result(nil); } else { result(FlutterMethodNotImplemented); } @@ -177,6 +180,11 @@ - (void)hide { self.webview.hidden = true; } } +- (void)stopLoading { + if (self.webview != nil) { + [self.webview stopLoading]; + } +} #pragma mark -- WkWebView Delegate - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction