Skip to content

Added reloading (Android) #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 24, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
12 changes: 12 additions & 0 deletions lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down