Skip to content

Commit 1e5a23e

Browse files
authored
Merge pull request #2 from pedia/schema
fix document
2 parents d2fd59e + 09ae5ab commit 1e5a23e

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

example/lib/main.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import 'package:flutter/material.dart';
44

55
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
66

7+
const kAndroidUserAgent =
8+
"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";
9+
710
void main() {
811
runApp(new MyApp());
912
}
@@ -46,7 +49,7 @@ class _MyHomePageState extends State<MyHomePage> {
4649
new TextEditingController(text: "http://github.com");
4750

4851
TextEditingController _codeCtrl =
49-
new TextEditingController(text: "window.location.href");
52+
new TextEditingController(text: "window.navigator.userAgent");
5053

5154
GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();
5255

@@ -111,7 +114,8 @@ class _MyHomePageState extends State<MyHomePage> {
111114
flutterWebviewPlugin.launch(_urlCtrl.text,
112115
fullScreen: false,
113116
rect: new Rect.fromLTWH(
114-
0.0, 0.0, MediaQuery.of(context).size.width, 300.0));
117+
0.0, 0.0, MediaQuery.of(context).size.width, 300.0),
118+
userAgent: kAndroidUserAgent);
115119
},
116120
child: new Text("Open Webview (rect)"),
117121
),

ios/Classes/FlutterWebviewPlugin.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ - (void)initWebView:(FlutterMethodCall*)call {
5959
NSNumber *hidden = call.arguments[@"hidden"];
6060
NSDictionary *rect = call.arguments[@"rect"];
6161
_enableAppScheme = call.arguments[@"enableAppScheme"];
62+
NSString *userAgent = call.arguments[@"userAgent"];
6263

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

84+
if (userAgent) {
85+
[[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent": userAgent}];
86+
}
87+
8388
self.webview = [[UIWebView alloc] initWithFrame:rc];
8489
self.webview.delegate = self;
8590

lib/flutter_webview_plugin.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ enum _WebViewNavigateType {
2424
class FlutterWebViewPlugin {
2525
final MethodChannel _channel;
2626

27+
/// iOS WebView: Implemented
28+
/// Android WebView: not implemented
2729
final EventChannel _event;
2830
Stream<String> _stateChanged;
2931

@@ -96,39 +98,45 @@ class FlutterWebViewPlugin {
9698
/// android: Implemented.
9799
/// - [clearCache] clear the cache of the Webview
98100
/// iOS WebView: Not implemented yet
99-
/// iOS WKWebView: will implement later
101+
/// iOS WkWebView: TODO: later
100102
/// android: Implemented
101103
/// - [clearCookies] clear all cookies of the Webview
102104
/// iOS WebView: Not implemented yet
103-
/// iOS WKWebView: will implement later
105+
/// iOS WkWebView: will implement later
104106
/// android: Implemented
105107
/// - [hidden] not show
106108
/// iOS WebView: not shown(addSubView) in ViewController
107-
/// android: Implemented
109+
/// android: Not implemented yet.
108110
/// [fullScreen]: show in full screen mode, default true
109111
/// iOS WebView: without rect, show in full screen mode
110-
/// android: Not implemented yet
112+
/// android: Implemented
111113
/// [rect]: show in rect(not full screen)
112114
/// iOS WebView: worked
113115
/// android: Not implemented yet
114-
/// [enableAppScheme]: false will enable all schemes, true only for
115-
/// httt/https/about
116+
/// [enableAppScheme]: false will enable all schemes, true only for httt/https/about
117+
/// iOS WebView: worked
118+
/// android: Not implemented yet
119+
/// [userAgent]: set the User-Agent of WebView
120+
/// iOS WebView: worked
121+
/// android: Not implemented yet
116122
Future<Null> launch(String url,
117123
{bool withJavascript: true,
118124
bool clearCache: false,
119125
bool clearCookies: false,
120126
bool hidden: false,
121127
bool fullScreen: true,
122128
bool enableAppScheme: true,
123-
Rect rect: null}) async {
129+
Rect rect: null,
130+
String userAgent: null}) async {
124131
Map<String, dynamic> args = {
125132
"url": url,
126133
"withJavascript": withJavascript,
127134
"clearCache": clearCache,
128135
"hidden": hidden,
129136
"clearCookies": clearCookies,
130137
"fullScreen": fullScreen,
131-
"enableAppScheme": enableAppScheme
138+
"enableAppScheme": enableAppScheme,
139+
"userAgent": userAgent
132140
};
133141
if (!fullScreen) assert(rect != null);
134142
if (rect != null) {
@@ -142,6 +150,8 @@ class FlutterWebViewPlugin {
142150
await _channel.invokeMethod('launch', args);
143151
}
144152

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

153163
/// Listening url changed
154-
///
164+
/// iOS WebView: worked
165+
/// android: worked
155166
Stream<String> get onUrlChanged => _onUrlChanged.stream;
156167
}

0 commit comments

Comments
 (0)