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 1cbac2c7..15beb933 100644 --- a/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java +++ b/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java @@ -48,6 +48,15 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { case "resize": resize(call, result); break; + case "reload": + reload(call, result); + break; + case "back": + back(call, result); + break; + case "forward": + forward(call, result); + break; default: result.notImplemented(); break; @@ -111,6 +120,31 @@ private void close(MethodCall call, MethodChannel.Result result) { } } + /** + * Navigates back on the Webview. + */ + private void back(MethodCall call, MethodChannel.Result result) { + if (webViewManager != null) { + webViewManager.back(call, result); + } + } + /** + * Navigates forward on the Webview. + */ + private void forward(MethodCall call, MethodChannel.Result result) { + if (webViewManager != null) { + webViewManager.forward(call, result); + } + } + + /** + * Reloads the Webview. + */ + private void reload(MethodCall call, MethodChannel.Result result) { + if (webViewManager != null) { + webViewManager.reload(call, result); + } + } private void eval(MethodCall call, final MethodChannel.Result result) { if (webViewManager != null) { webViewManager.eval(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 3c645124..489cbf95 100644 --- a/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java +++ b/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java @@ -122,8 +122,44 @@ public void onReceiveValue(String value) { } }); } + /** + * Reloads the Webview. + */ + void reload(MethodCall call, MethodChannel.Result result) { + if (webView != null) { + webView.reload(); + } + } + /** + * Navigates back on the Webview. + */ + void back(MethodCall call, MethodChannel.Result result) { + if (webView != null && webView.canGoBack()) { + webView.goBack(); + } + } + /** + * Navigates forward on the Webview. + */ + void forward(MethodCall call, MethodChannel.Result result) { + if (webView != null && webView.canGoForward()) { + webView.goForward(); + } + } void resize(FrameLayout.LayoutParams params) { webView.setLayoutParams(params); } + /** + * Checks if going back on the Webview is possible. + */ + boolean canGoBack() { + return webView.canGoBack(); + } + /** + * Checks if going forward on the Webview is possible. + */ + boolean canGoForward() { + return webView.canGoForward(); + } } diff --git a/lib/src/base.dart b/lib/src/base.dart index 7d93e953..abcc8365 100644 --- a/lib/src/base.dart +++ b/lib/src/base.dart @@ -113,6 +113,18 @@ class FlutterWebviewPlugin { /// Will trigger the [onDestroy] event Future close() => _channel.invokeMethod("close"); + /// Reloads the WebView. + /// This is only available on Android for now. + Future reload() => _channel.invokeMethod("reload"); + + /// Navigates back on the Webview. + /// This is only available on Android for now. + Future goBack() => _channel.invokeMethod("back"); + + /// Navigates forward on the Webview. + /// This is only available on Android for now. + Future goForward() => _channel.invokeMethod("forward"); + /// Close all Streams void dispose() { _onDestroy.close();