Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions ios/Classes/FlutterWebviewPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions lib/src/base.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<Null> launch(String url,
{bool withJavascript,
bool clearCache,
Expand All @@ -80,7 +82,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,
Expand All @@ -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"] = {
Expand Down
7 changes: 5 additions & 2 deletions lib/src/webview_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class WebviewScaffold extends StatefulWidget {
final Widget bottomNavigationBar;
final bool withZoom;
final bool withLocalStorage;
final bool withLocalUrl;

WebviewScaffold(
{Key key,
Expand All @@ -32,7 +33,8 @@ class WebviewScaffold extends StatefulWidget {
this.persistentFooterButtons,
this.bottomNavigationBar,
this.withZoom,
this.withLocalStorage})
this.withLocalStorage,
this.withLocalUrl})
: super(key: key);

@override
Expand Down Expand Up @@ -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) {
Expand Down