Explorar o código

Merge pull request #51 from jparound30/feature_support_localstorage

support LocalStorage
Hadrien Lejard %!s(int64=7) %!d(string=hai) anos
pai
achega
839bbe6b90

+ 3 - 1
android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

@@ -62,6 +62,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler {
         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 @@ public class FlutterWebviewPlugin implements MethodCallHandler {
                 clearCookies,
                 userAgent,
                 url,
-                withZoom
+                withZoom,
+                withLocalStorage
         );
         result.success(null);
     }

+ 2 - 1
android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

@@ -68,10 +68,11 @@ class WebviewManager {
         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();

+ 1 - 0
example/lib/main.dart

@@ -29,6 +29,7 @@ class MyApp extends StatelessWidget {
                 title: new Text("Widget webview"),
               ),
               withZoom: true,
+              withLocalStorage: true,
             )
       },
     );

+ 7 - 2
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<Null> 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<String, dynamic> 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"] = {

+ 5 - 2
lib/src/webview_scaffold.dart

@@ -17,6 +17,7 @@ class WebviewScaffold extends StatefulWidget {
   final List<Widget> 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<WebviewScaffold> {
           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) {