Skip to content

Commit 5b3c3e1

Browse files
authored
Merge branch 'master' into progress
2 parents 3e1d028 + 08ca8f0 commit 5b3c3e1

File tree

10 files changed

+211
-132
lines changed

10 files changed

+211
-132
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Future<Null> launch(String url,
143143
String userAgent: null,
144144
bool withZoom: false,
145145
bool withLocalStorage: true,
146+
bool withLocalUrl: true,
146147
bool scrollBar: true});
147148
```
148149
```dart

android/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.1.2'
11+
classpath 'com.android.tools.build:gradle:3.2.1'
1212
}
1313
}
1414

@@ -21,8 +21,7 @@ allprojects {
2121
apply plugin: 'com.android.library'
2222

2323
android {
24-
compileSdkVersion 25
25-
buildToolsVersion '27.0.3'
24+
compileSdkVersion 27
2625

2726
defaultConfig {
2827
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

example/android/app/build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
1616

1717
android {
1818
compileSdkVersion 27
19-
buildToolsVersion '27.0.3'
2019

2120
lintOptions {
2221
disable 'InvalidPackage'
2322
}
2423

2524
defaultConfig {
2625
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
27-
2826
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
2927
applicationId "com.yourcompany.flutter_webview_plugin_example"
3028
}
@@ -43,7 +41,7 @@ flutter {
4341
}
4442

4543
dependencies {
46-
androidTestCompile 'com.android.support:support-annotations:25.0.0'
47-
androidTestCompile 'com.android.support.test:runner:0.5'
48-
androidTestCompile 'com.android.support.test:rules:0.5'
44+
androidTestImplementation 'com.android.support:support-annotations:27.0.0'
45+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
46+
androidTestImplementation 'com.android.support.test:rules:1.0.2'
4947
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
android:versionCode="1"
44
android:versionName="0.0.1">
55

6-
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7-
86
<!-- The INTERNET permission is required for development. Specifically,
97
flutter needs it to communicate with the running application
108
to allow setting breakpoints, to provide hot reload, etc.

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.1.1'
11+
classpath 'com.android.tools.build:gradle:3.2.1'
1212
}
1313
}
1414

example/lib/main.dart

Lines changed: 92 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ void main() {
1414
}
1515

1616
class MyApp extends StatelessWidget {
17+
final flutterWebviewPlugin = new FlutterWebviewPlugin();
18+
1719
@override
1820
Widget build(BuildContext context) {
1921
return new MaterialApp(
@@ -37,6 +39,29 @@ class MyApp extends StatelessWidget {
3739
child: Text('Waiting.....'),
3840
),
3941
),
42+
bottomNavigationBar: BottomAppBar(
43+
child: Row(
44+
children: <Widget>[
45+
IconButton(
46+
icon: const Icon(Icons.arrow_back_ios),
47+
onPressed: () {
48+
flutterWebviewPlugin.goBack();
49+
},
50+
),
51+
IconButton(
52+
icon: const Icon(Icons.arrow_forward_ios),
53+
onPressed: () {
54+
flutterWebviewPlugin.goForward();
55+
},
56+
),
57+
IconButton(
58+
icon: const Icon(Icons.autorenew),
59+
onPressed: () {
60+
flutterWebviewPlugin.reload();
61+
},
62+
),
63+
],
64+
)),
4065
)
4166
},
4267
);
@@ -168,77 +193,76 @@ class _MyHomePageState extends State<MyHomePage> {
168193
appBar: new AppBar(
169194
title: const Text('Plugin example app'),
170195
),
171-
body: new Column(
172-
mainAxisAlignment: MainAxisAlignment.center,
173-
children: [
174-
new Container(
175-
padding: const EdgeInsets.all(24.0),
176-
child: new TextField(controller: _urlCtrl),
177-
),
178-
new RaisedButton(
179-
onPressed: () {
180-
flutterWebviewPlugin.launch(selectedUrl,
181-
rect: new Rect.fromLTWH(
182-
0.0, 0.0, MediaQuery.of(context).size.width, 300.0),
183-
userAgent: kAndroidUserAgent);
184-
},
185-
child: const Text('Open Webview (rect)'),
186-
),
187-
new RaisedButton(
188-
onPressed: () {
189-
flutterWebviewPlugin.launch(selectedUrl, hidden: true);
190-
},
191-
child: const Text('Open "hidden" Webview'),
192-
),
193-
new RaisedButton(
194-
onPressed: () {
195-
flutterWebviewPlugin.launch(selectedUrl);
196-
},
197-
child: const Text('Open Fullscreen Webview'),
198-
),
199-
new RaisedButton(
200-
onPressed: () {
201-
Navigator.of(context).pushNamed('/widget');
202-
},
203-
child: const Text('Open widget webview'),
204-
),
205-
new Container(
206-
padding: const EdgeInsets.all(24.0),
207-
child: new TextField(controller: _codeCtrl),
208-
),
209-
new RaisedButton(
210-
onPressed: () {
211-
final future =
212-
flutterWebviewPlugin.evalJavascript(_codeCtrl.text);
213-
future.then((String result) {
214-
setState(() {
215-
_history.add('eval: $result');
196+
body: SingleChildScrollView(
197+
child: new Column(
198+
mainAxisAlignment: MainAxisAlignment.center,
199+
children: [
200+
new Container(
201+
padding: const EdgeInsets.all(24.0),
202+
child: new TextField(controller: _urlCtrl),
203+
),
204+
new RaisedButton(
205+
onPressed: () {
206+
flutterWebviewPlugin.launch(selectedUrl,
207+
rect: new Rect.fromLTWH(0.0, 0.0, MediaQuery.of(context).size.width, 300.0), userAgent: kAndroidUserAgent);
208+
},
209+
child: const Text('Open Webview (rect)'),
210+
),
211+
new RaisedButton(
212+
onPressed: () {
213+
flutterWebviewPlugin.launch(selectedUrl, hidden: true);
214+
},
215+
child: const Text('Open "hidden" Webview'),
216+
),
217+
new RaisedButton(
218+
onPressed: () {
219+
flutterWebviewPlugin.launch(selectedUrl);
220+
},
221+
child: const Text('Open Fullscreen Webview'),
222+
),
223+
new RaisedButton(
224+
onPressed: () {
225+
Navigator.of(context).pushNamed('/widget');
226+
},
227+
child: const Text('Open widget webview'),
228+
),
229+
new Container(
230+
padding: const EdgeInsets.all(24.0),
231+
child: new TextField(controller: _codeCtrl),
232+
),
233+
new RaisedButton(
234+
onPressed: () {
235+
final future = flutterWebviewPlugin.evalJavascript(_codeCtrl.text);
236+
future.then((String result) {
237+
setState(() {
238+
_history.add('eval: $result');
239+
});
216240
});
217-
});
218-
},
219-
child: const Text('Eval some javascript'),
220-
),
221-
new RaisedButton(
222-
onPressed: () {
223-
setState(() {
224-
_history.clear();
225-
});
226-
flutterWebviewPlugin.close();
227-
},
228-
child: const Text('Close'),
229-
),
230-
new RaisedButton(
231-
onPressed: () {
232-
flutterWebviewPlugin.getCookies().then((m) {
241+
},
242+
child: const Text('Eval some javascript'),
243+
),
244+
new RaisedButton(
245+
onPressed: () {
233246
setState(() {
234-
_history.add('cookies: $m');
247+
_history.clear();
248+
});
249+
flutterWebviewPlugin.close();
250+
},
251+
child: const Text('Close'),
252+
),
253+
new RaisedButton(
254+
onPressed: () {
255+
flutterWebviewPlugin.getCookies().then((m) {
256+
setState(() {
257+
_history.add('cookies: $m');
258+
});
235259
});
236-
});
237-
},
238-
child: const Text('Cookies'),
239-
),
240-
new Text(_history.join('\n'))
241-
],
260+
},
261+
child: const Text('Cookies'),
262+
),
263+
new Text(_history.join('\n'))
264+
],
265+
),
242266
),
243267
);
244268
}

ios/Classes/FlutterWebviewPlugin.m

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
1515
methodChannelWithName:CHANNEL_NAME
1616
binaryMessenger:[registrar messenger]];
1717

18-
UIViewController *viewController = (UIViewController *)registrar.messenger;
18+
UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
1919
FlutterWebviewPlugin* instance = [[FlutterWebviewPlugin alloc] initWithViewController:viewController];
2020

2121
[registrar addMethodCallDelegate:instance channel:channel];
@@ -58,6 +58,15 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
5858
} else if ([@"stopLoading" isEqualToString:call.method]) {
5959
[self stopLoading];
6060
result(nil);
61+
} else if ([@"back" isEqualToString:call.method]) {
62+
[self back];
63+
result(nil);
64+
} else if ([@"forward" isEqualToString:call.method]) {
65+
[self forward];
66+
result(nil);
67+
} else if ([@"reload" isEqualToString:call.method]) {
68+
[self reload];
69+
result(nil);
6170
} else {
6271
result(FlutterMethodNotImplemented);
6372
}
@@ -204,6 +213,21 @@ - (void)stopLoading {
204213
[self.webview stopLoading];
205214
}
206215
}
216+
- (void)back {
217+
if (self.webview != nil) {
218+
[self.webview goBack];
219+
}
220+
}
221+
- (void)forward {
222+
if (self.webview != nil) {
223+
[self.webview goForward];
224+
}
225+
}
226+
- (void)reload {
227+
if (self.webview != nil) {
228+
[self.webview reload];
229+
}
230+
}
207231

208232
#pragma mark -- WkWebView Delegate
209233
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction

lib/src/base.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,12 @@ class FlutterWebviewPlugin {
148148
Future close() => _channel.invokeMethod('close');
149149

150150
/// Reloads the WebView.
151-
/// This is only available on Android for now.
152151
Future reload() => _channel.invokeMethod('reload');
153152

154153
/// Navigates back on the Webview.
155-
/// This is only available on Android for now.
156154
Future goBack() => _channel.invokeMethod('back');
157155

158156
/// Navigates forward on the Webview.
159-
/// This is only available on Android for now.
160157
Future goForward() => _channel.invokeMethod('forward');
161158

162159
// Hides the webview

0 commit comments

Comments
 (0)