Skip to content

Commit eb95686

Browse files
author
Andrei Bosco
committed
Applying changes by flutter#1247 and adapting them to work with webview_flutter 0.3.9 (android only for now)
1 parent 8043b07 commit eb95686

5 files changed

Lines changed: 46 additions & 2 deletions

File tree

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
4848

4949
if (params.containsKey("initialUrl")) {
5050
String url = (String) params.get("initialUrl");
51-
webView.loadUrl(url);
51+
// webView.loadUrl(url);
52+
if (url.contains("://"))
53+
webView.loadUrl(url);
54+
else
55+
webView.loadUrl("file:///android_asset/flutter_assets/" + url);
5256
}
5357
}
5458

@@ -63,6 +67,9 @@ public void onMethodCall(MethodCall methodCall, Result result) {
6367
case "loadUrl":
6468
loadUrl(methodCall, result);
6569
break;
70+
case "loadAssetFile":
71+
loadAssetFile(methodCall, result);
72+
break;
6673
case "updateSettings":
6774
updateSettings(methodCall, result);
6875
break;
@@ -113,6 +120,12 @@ private void loadUrl(MethodCall methodCall, Result result) {
113120
result.success(null);
114121
}
115122

123+
private void loadAssetFile(MethodCall methodCall, Result result) {
124+
String url = (String) methodCall.arguments;
125+
webView.loadUrl("file:///android_asset/flutter_assets/" + url);
126+
result.success(null);
127+
}
128+
116129
private void canGoBack(Result result) {
117130
result.success(webView.canGoBack());
118131
}

packages/webview_flutter/lib/platform_interface.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ abstract class WebViewPlatformController {
5555
"WebView loadUrl is not implemented on the current platform");
5656
}
5757

58+
Future<void> loadAssetFile(
59+
String url,
60+
) {
61+
throw UnimplementedError(
62+
"WebView loadAssetFile is not implemented on the current platform");
63+
}
64+
5865
/// Updates the webview settings.
5966
///
6067
/// Any non null field in `settings` will be set as the new setting value.

packages/webview_flutter/lib/src/webview_method_channel.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController {
5858
});
5959
}
6060

61+
@override
62+
Future<void> loadAssetFile(
63+
String url,
64+
) async {
65+
assert(url != null);
66+
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
67+
// https://github.com/flutter/flutter/issues/26431
68+
// ignore: strong_mode_implicit_dynamic_method
69+
return _channel.invokeMethod('loadAssetFile', {
70+
'url': url,
71+
});
72+
}
73+
6174
@override
6275
Future<String> currentUrl() => _channel.invokeMethod('currentUrl');
6376

packages/webview_flutter/lib/webview_flutter.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,17 @@ class WebViewController {
446446
return _webViewPlatformController.loadUrl(url, headers);
447447
}
448448

449+
/// Loads the specified file.
450+
///
451+
/// `url` must not be null.
452+
Future<void> loadAssetFile(String url) async {
453+
assert(url != null);
454+
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
455+
// https://github.com/flutter/flutter/issues/26431
456+
// ignore: strong_mode_implicit_dynamic_method
457+
return _webViewPlatformController.loadAssetFile(url);
458+
}
459+
449460
/// Accessor to the current URL that the WebView is displaying.
450461
///
451462
/// If [WebView.initialUrl] was never specified, returns `null`.

packages/webview_flutter/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: webview_flutter
22
description: A Flutter plugin that provides a WebView widget on Android and iOS.
3-
version: 0.3.9
3+
version: 0.3.9+1
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter
66

0 commit comments

Comments
 (0)