Bladeren bron

allow locale file

Yann-Cyril PELUD 7 jaren geleden
bovenliggende
commit
8d24d07357
3 gewijzigde bestanden met toevoegingen van 24 en 9 verwijderingen
  1. 14 4
      ios/Classes/FlutterWebviewPlugin.m
  2. 5 3
      lib/src/base.dart
  3. 5 2
      lib/src/webview_scaffold.dart

+ 14 - 4
ios/Classes/FlutterWebviewPlugin.m

@@ -101,10 +101,20 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
 
 - (void)navigate:(FlutterMethodCall*)call {
     if (self.webview != nil) {
-        NSString *url = call.arguments[@"url"];
-        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
-        [self.webview loadRequest:request];
-    }
+            NSString *url = call.arguments[@"url"];
+            NSNumber *withLocalUrl = call.arguments[@"withLocalUrl"];
+            if ( [withLocalUrl boolValue]) {
+                NSURL *htmlUrl = [NSURL fileURLWithPath:url isDirectory:false];
+                if (@available(iOS 9.0, *)) {
+                    [self.webview loadFileURL:htmlUrl allowingReadAccessToURL:htmlUrl];
+                } else {
+                    @throw @"not available on version earlier than ios 9.0";
+                }
+            } else {
+                NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
+                [self.webview loadRequest:request];
+            }
+        }
 }
 
 - (void)evalJavascript:(FlutterMethodCall*)call

+ 5 - 3
lib/src/base.dart

@@ -1,8 +1,8 @@
 import 'dart:async';
 import 'dart:ui';
 
-import 'package:flutter/services.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 
 const _kChannel = 'flutter_webview_plugin';
 
@@ -80,7 +80,8 @@ class FlutterWebviewPlugin {
       Rect rect,
       String userAgent,
       bool withZoom,
-      bool withLocalStorage}) async {
+      bool withLocalStorage,
+      bool withLocalUrl}) async {
     Map<String, dynamic> args = {
       "url": url,
       "withJavascript": withJavascript ?? true,
@@ -90,7 +91,8 @@ class FlutterWebviewPlugin {
       "enableAppScheme": enableAppScheme ?? true,
       "userAgent": userAgent,
       "withZoom": withZoom ?? false,
-      "withLocalStorage": withLocalStorage ?? true
+      "withLocalStorage": withLocalStorage ?? true,
+      "withLocalUrl": withLocalUrl ?? false
     };
     if (rect != null) {
       args["rect"] = {

+ 5 - 2
lib/src/webview_scaffold.dart

@@ -18,6 +18,7 @@ class WebviewScaffold extends StatefulWidget {
   final Widget bottomNavigationBar;
   final bool withZoom;
   final bool withLocalStorage;
+  final bool withLocalUrl;
 
   WebviewScaffold(
       {Key key,
@@ -32,7 +33,8 @@ class WebviewScaffold extends StatefulWidget {
       this.persistentFooterButtons,
       this.bottomNavigationBar,
       this.withZoom,
-      this.withLocalStorage})
+      this.withLocalStorage,
+      this.withLocalUrl})
       : super(key: key);
 
   @override
@@ -67,7 +69,8 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
           userAgent: widget.userAgent,
           rect: _rect,
           withZoom: widget.withZoom,
-          withLocalStorage: widget.withLocalStorage);
+          withLocalStorage: widget.withLocalStorage,
+          withLocalUrl: widget.withLocalUrl);
     } else {
       Rect rect = _buildRect(context);
       if (_rect != rect) {