Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update FlutterWebView.java
  • Loading branch information
uc-apa authored May 2, 2020
commit 5861fa35a7404933182716e2e7363af39137b0ff
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
private final MethodChannel methodChannel;
private final FlutterWebViewClient flutterWebViewClient;
private final Handler platformThreadHandler;
private String baseUrl;

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -68,7 +69,7 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
if (params.containsKey("html")) {
String html = (String) params.get("html");
if (params.containsKey("baseUrl")) {
String baseUrl = (String) params.get("baseUrl");
baseUrl = (String) params.get("baseUrl");
webView.loadDataWithBaseURL(baseUrl, html, "text/html", "UTF-8", null);
} else {
webView.loadData(html, "text/html", "UTF-8");
Expand Down Expand Up @@ -130,6 +131,9 @@ public void onMethodCall(MethodCall methodCall, Result result) {
case "loadUrl":
loadUrl(methodCall, result);
break;
case "loadHtml":
loadHtml(methodCall, result);
break;
case "updateSettings":
updateSettings(methodCall, result);
break;
Expand Down Expand Up @@ -195,6 +199,20 @@ private void loadUrl(MethodCall methodCall, Result result) {
result.success(null);
}

@SuppressWarnings("unchecked")
private void loadHtml(MethodCall methodCall, Result result) {
Map<String, Object> request = (Map<String, Object>) methodCall.arguments;
String html = (String) request.get("html");
if (html != null) {
if (baseUrl != null) {
webView.loadDataWithBaseURL(baseUrl, html, "text/html", "UTF-8", null);
} else {
webView.loadData(html, "text/html", "UTF-8");
}
}
result.success(null);
}

private void canGoBack(Result result) {
result.success(webView.canGoBack());
}
Expand Down