Procházet zdrojové kódy

Merge pull request #217 from rydein/master

add back, forward, reload method on iOS
Simon Lightfoot před 7 roky
rodič
revize
1f19f7cd2b
3 změnil soubory, kde provedl 49 přidání a 3 odebrání
  1. 25 0
      example/lib/main.dart
  2. 24 0
      ios/Classes/FlutterWebviewPlugin.m
  3. 0 3
      lib/src/base.dart

+ 25 - 0
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: <Widget>[
+                  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();
+                    },
+                  ),
+                ],
+              )),
             )
       },
     );

+ 24 - 0
ios/Classes/FlutterWebviewPlugin.m

@@ -58,6 +58,15 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     } 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 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
         [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

+ 0 - 3
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