diff --git a/ios/Classes/FlutterWebviewPlugin.m b/ios/Classes/FlutterWebviewPlugin.m index 0f4649c6..c2cbe9ee 100644 --- a/ios/Classes/FlutterWebviewPlugin.m +++ b/ios/Classes/FlutterWebviewPlugin.m @@ -101,10 +101,20 @@ - (CGRect)parseRect:(NSDictionary *)rect { - (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 diff --git a/lib/src/base.dart b/lib/src/base.dart index 7d93e953..f0baa73f 100644 --- a/lib/src/base.dart +++ b/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'; @@ -71,6 +71,8 @@ class FlutterWebviewPlugin { /// - [withLocalStorage] enable localStorage API on Webview /// Currently Android only. /// It is always enabled in UIWebView of iOS and can not be disabled. + /// - [withLocalUrl]: allow url as a local path + /// Allow local files on iOs > 9.0 Future launch(String url, {bool withJavascript, bool clearCache, @@ -80,7 +82,8 @@ class FlutterWebviewPlugin { Rect rect, String userAgent, bool withZoom, - bool withLocalStorage}) async { + bool withLocalStorage, + bool withLocalUrl}) async { Map args = { "url": url, "withJavascript": withJavascript ?? true, @@ -90,7 +93,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"] = { diff --git a/lib/src/webview_scaffold.dart b/lib/src/webview_scaffold.dart index 2817fff6..d412fa41 100644 --- a/lib/src/webview_scaffold.dart +++ b/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 { 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) {