Skip to content

Commit

Permalink
Merge pull request #2 from pedia/schema
Browse files Browse the repository at this point in the history
fix document
  • Loading branch information
pedia authored Dec 15, 2017
2 parents 7ea334d + dfd1d0e commit 571e3aa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
8 changes: 6 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import 'package:flutter/material.dart';

import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

const kAndroidUserAgent =
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36";

void main() {
runApp(new MyApp());
}
Expand Down Expand Up @@ -46,7 +49,7 @@ class _MyHomePageState extends State<MyHomePage> {
new TextEditingController(text: "http://github.com");

TextEditingController _codeCtrl =
new TextEditingController(text: "window.location.href");
new TextEditingController(text: "window.navigator.userAgent");

GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();

Expand Down Expand Up @@ -111,7 +114,8 @@ class _MyHomePageState extends State<MyHomePage> {
flutterWebviewPlugin.launch(_urlCtrl.text,
fullScreen: false,
rect: new Rect.fromLTWH(
0.0, 0.0, MediaQuery.of(context).size.width, 300.0));
0.0, 0.0, MediaQuery.of(context).size.width, 300.0),
userAgent: kAndroidUserAgent);
},
child: new Text("Open Webview (rect)"),
),
Expand Down
5 changes: 5 additions & 0 deletions ios/Classes/FlutterWebviewPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ - (void)initWebView:(FlutterMethodCall*)call {
NSNumber *hidden = call.arguments[@"hidden"];
NSDictionary *rect = call.arguments[@"rect"];
_enableAppScheme = call.arguments[@"enableAppScheme"];
NSString *userAgent = call.arguments[@"userAgent"];

//
if ([clearCache boolValue]) {
Expand All @@ -80,6 +81,10 @@ - (void)initWebView:(FlutterMethodCall*)call {
rc = self.viewController.view.bounds;
}

if (userAgent) {
[[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent": userAgent}];
}

self.webview = [[UIWebView alloc] initWithFrame:rc];
self.webview.delegate = self;

Expand Down
29 changes: 20 additions & 9 deletions lib/flutter_webview_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum _WebViewNavigateType {
class FlutterWebViewPlugin {
final MethodChannel _channel;

/// iOS WebView: Implemented
/// Android WebView: not implemented
final EventChannel _event;
Stream<String> _stateChanged;

Expand Down Expand Up @@ -96,39 +98,45 @@ class FlutterWebViewPlugin {
/// android: Implemented.
/// - [clearCache] clear the cache of the Webview
/// iOS WebView: Not implemented yet
/// iOS WKWebView: will implement later
/// iOS WkWebView: TODO: later
/// android: Implemented
/// - [clearCookies] clear all cookies of the Webview
/// iOS WebView: Not implemented yet
/// iOS WKWebView: will implement later
/// iOS WkWebView: will implement later
/// android: Implemented
/// - [hidden] not show
/// iOS WebView: not shown(addSubView) in ViewController
/// android: Implemented
/// android: Not implemented yet.
/// [fullScreen]: show in full screen mode, default true
/// iOS WebView: without rect, show in full screen mode
/// android: Not implemented yet
/// android: Implemented
/// [rect]: show in rect(not full screen)
/// iOS WebView: worked
/// android: Not implemented yet
/// [enableAppScheme]: false will enable all schemes, true only for
/// httt/https/about
/// [enableAppScheme]: false will enable all schemes, true only for httt/https/about
/// iOS WebView: worked
/// android: Not implemented yet
/// [userAgent]: set the User-Agent of WebView
/// iOS WebView: worked
/// android: Not implemented yet
Future<Null> launch(String url,
{bool withJavascript: true,
bool clearCache: false,
bool clearCookies: false,
bool hidden: false,
bool fullScreen: true,
bool enableAppScheme: true,
Rect rect: null}) async {
Rect rect: null,
String userAgent: null}) async {
Map<String, dynamic> args = {
"url": url,
"withJavascript": withJavascript,
"clearCache": clearCache,
"hidden": hidden,
"clearCookies": clearCookies,
"fullScreen": fullScreen,
"enableAppScheme": enableAppScheme
"enableAppScheme": enableAppScheme,
"userAgent": userAgent
};
if (!fullScreen) assert(rect != null);
if (rect != null) {
Expand All @@ -142,6 +150,8 @@ class FlutterWebViewPlugin {
await _channel.invokeMethod('launch', args);
}

/// iOS WebView: worked
/// android: Not implemented yet
Future<String> evalJavascript(String code) {
return _channel.invokeMethod('eval', {"code": code});
}
Expand All @@ -151,6 +161,7 @@ class FlutterWebViewPlugin {
Future<Null> close() => _channel.invokeMethod("close");

/// Listening url changed
///
/// iOS WebView: worked
/// android: worked
Stream<String> get onUrlChanged => _onUrlChanged.stream;
}

0 comments on commit 571e3aa

Please sign in to comment.