Skip to content

Commit ffe6b33

Browse files
committed
add back, forward, reload method on iOS
1 parent f0e8e71 commit ffe6b33

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

example/lib/main.dart

Lines changed: 25 additions & 0 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(
@@ -30,6 +32,29 @@ class MyApp extends StatelessWidget {
3032
),
3133
withZoom: true,
3234
withLocalStorage: true,
35+
bottomNavigationBar: BottomAppBar(
36+
child: Row(
37+
children: <Widget>[
38+
IconButton(
39+
icon: const Icon(Icons.arrow_back_ios),
40+
onPressed: () {
41+
flutterWebviewPlugin.goBack();
42+
},
43+
),
44+
IconButton(
45+
icon: const Icon(Icons.arrow_forward_ios),
46+
onPressed: () {
47+
flutterWebviewPlugin.goForward();
48+
},
49+
),
50+
IconButton(
51+
icon: const Icon(Icons.autorenew),
52+
onPressed: () {
53+
flutterWebviewPlugin.reload();
54+
},
55+
),
56+
],
57+
)),
3358
)
3459
},
3560
);

ios/Classes/FlutterWebviewPlugin.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)