From ffe6b33d6e28eb5d7be9f2be6dd7097985a55a54 Mon Sep 17 00:00:00 2001 From: rydein Date: Tue, 30 Oct 2018 00:11:28 +0900 Subject: [PATCH] add back, forward, reload method on iOS --- example/lib/main.dart | 25 +++++++++++++++++++++++++ ios/Classes/FlutterWebviewPlugin.m | 24 ++++++++++++++++++++++++ lib/src/base.dart | 3 --- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 90a9c46c..715ab1f4 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -14,6 +14,8 @@ void main() { } class MyApp extends StatelessWidget { + final flutterWebviewPlugin = new FlutterWebviewPlugin(); + @override Widget build(BuildContext context) { return new MaterialApp( @@ -30,6 +32,29 @@ class MyApp extends StatelessWidget { ), withZoom: true, withLocalStorage: true, + bottomNavigationBar: BottomAppBar( + child: Row( + children: [ + IconButton( + icon: const Icon(Icons.arrow_back_ios), + onPressed: () { + flutterWebviewPlugin.goBack(); + }, + ), + IconButton( + icon: const Icon(Icons.arrow_forward_ios), + onPressed: () { + flutterWebviewPlugin.goForward(); + }, + ), + IconButton( + icon: const Icon(Icons.autorenew), + onPressed: () { + flutterWebviewPlugin.reload(); + }, + ), + ], + )), ) }, ); diff --git a/ios/Classes/FlutterWebviewPlugin.m b/ios/Classes/FlutterWebviewPlugin.m index 7aeb18be..88de4be7 100644 --- a/ios/Classes/FlutterWebviewPlugin.m +++ b/ios/Classes/FlutterWebviewPlugin.m @@ -58,6 +58,15 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { } else if ([@"stopLoading" isEqualToString:call.method]) { [self stopLoading]; result(nil); + } else if ([@"back" isEqualToString:call.method]) { + [self back]; + result(nil); + } else if ([@"forward" isEqualToString:call.method]) { + [self forward]; + result(nil); + } else if ([@"reload" isEqualToString:call.method]) { + [self reload]; + result(nil); } else { result(FlutterMethodNotImplemented); } @@ -204,6 +213,21 @@ - (void)stopLoading { [self.webview stopLoading]; } } +- (void)back { + if (self.webview != nil) { + [self.webview goBack]; + } +} +- (void)forward { + if (self.webview != nil) { + [self.webview goForward]; + } +} +- (void)reload { + if (self.webview != nil) { + [self.webview reload]; + } +} #pragma mark -- WkWebView Delegate - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction diff --git a/lib/src/base.dart b/lib/src/base.dart index 59389035..4ea5f90e 100644 --- a/lib/src/base.dart +++ b/lib/src/base.dart @@ -148,15 +148,12 @@ class FlutterWebviewPlugin { Future close() => _channel.invokeMethod('close'); /// Reloads the WebView. - /// This is only available on Android for now. Future reload() => _channel.invokeMethod('reload'); /// Navigates back on the Webview. - /// This is only available on Android for now. Future goBack() => _channel.invokeMethod('back'); /// Navigates forward on the Webview. - /// This is only available on Android for now. Future goForward() => _channel.invokeMethod('forward'); // Hides the webview