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 a262bc27..1cbac2c7 100644 --- a/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java +++ b/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java @@ -62,6 +62,7 @@ private void openUrl(MethodCall call, MethodChannel.Result result) { boolean clearCache = call.argument("clearCache"); boolean clearCookies = call.argument("clearCookies"); boolean withZoom = call.argument("withZoom"); + boolean withLocalStorage = call.argument("withLocalStorage"); if (webViewManager == null || webViewManager.closed == true) { webViewManager = new WebviewManager(activity); @@ -77,7 +78,8 @@ private void openUrl(MethodCall call, MethodChannel.Result result) { clearCookies, userAgent, url, - withZoom + withZoom, + withLocalStorage ); result.success(null); } 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 bb22004a..3c645124 100644 --- a/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java +++ b/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java @@ -68,10 +68,11 @@ private void clearCache() { webView.clearFormData(); } - void openUrl(boolean withJavascript, boolean clearCache, boolean hidden, boolean clearCookies, String userAgent, String url, boolean withZoom) { + void openUrl(boolean withJavascript, boolean clearCache, boolean hidden, boolean clearCookies, String userAgent, String url, boolean withZoom, boolean withLocalStorage) { webView.getSettings().setJavaScriptEnabled(withJavascript); webView.getSettings().setBuiltInZoomControls(withZoom); webView.getSettings().setSupportZoom(withZoom); + webView.getSettings().setDomStorageEnabled(withLocalStorage); if (clearCache) { clearCache(); diff --git a/example/lib/main.dart b/example/lib/main.dart index ce982faa..67229530 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -29,6 +29,7 @@ class MyApp extends StatelessWidget { title: new Text("Widget webview"), ), withZoom: true, + withLocalStorage: true, ) }, ); diff --git a/lib/src/base.dart b/lib/src/base.dart index 22fed66d..7d93e953 100644 --- a/lib/src/base.dart +++ b/lib/src/base.dart @@ -68,6 +68,9 @@ class FlutterWebviewPlugin { /// android: Not implemented yet /// - [userAgent]: set the User-Agent of WebView /// - [withZoom]: enable zoom on webview + /// - [withLocalStorage] enable localStorage API on Webview + /// Currently Android only. + /// It is always enabled in UIWebView of iOS and can not be disabled. Future launch(String url, {bool withJavascript, bool clearCache, @@ -76,7 +79,8 @@ class FlutterWebviewPlugin { bool enableAppScheme, Rect rect, String userAgent, - bool withZoom}) async { + bool withZoom, + bool withLocalStorage}) async { Map args = { "url": url, "withJavascript": withJavascript ?? true, @@ -85,7 +89,8 @@ class FlutterWebviewPlugin { "clearCookies": clearCookies ?? false, "enableAppScheme": enableAppScheme ?? true, "userAgent": userAgent, - "withZoom": withZoom ?? false + "withZoom": withZoom ?? false, + "withLocalStorage": withLocalStorage ?? true }; if (rect != null) { args["rect"] = { diff --git a/lib/src/webview_scaffold.dart b/lib/src/webview_scaffold.dart index 50e4bbc2..2817fff6 100644 --- a/lib/src/webview_scaffold.dart +++ b/lib/src/webview_scaffold.dart @@ -17,6 +17,7 @@ class WebviewScaffold extends StatefulWidget { final List persistentFooterButtons; final Widget bottomNavigationBar; final bool withZoom; + final bool withLocalStorage; WebviewScaffold( {Key key, @@ -30,7 +31,8 @@ class WebviewScaffold extends StatefulWidget { this.primary: true, this.persistentFooterButtons, this.bottomNavigationBar, - this.withZoom}) + this.withZoom, + this.withLocalStorage}) : super(key: key); @override @@ -64,7 +66,8 @@ class _WebviewScaffoldState extends State { enableAppScheme: widget.enableAppScheme, userAgent: widget.userAgent, rect: _rect, - withZoom: widget.withZoom); + withZoom: widget.withZoom, + withLocalStorage: widget.withLocalStorage); } else { Rect rect = _buildRect(context); if (_rect != rect) {