Lejard Hadrien il y a 7 ans
Parent
commit
642b3c1f66

+ 4 - 0
CHANGELOG.md

@@ -1,3 +1,7 @@
+# 0.1.3
+
+- support zoom in webview
+
 # 0.1.2
 
 - support bottomNavigationBar and persistentFooterButtons on webview scaffold

+ 3 - 1
android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

@@ -61,6 +61,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler {
         boolean withJavascript = call.argument("withJavascript");
         boolean clearCache = call.argument("clearCache");
         boolean clearCookies = call.argument("clearCookies");
+        boolean withZoom = call.argument("withZoom");
 
         if (webViewManager == null || webViewManager.closed == true) {
             webViewManager = new WebviewManager(activity);
@@ -75,7 +76,8 @@ public class FlutterWebviewPlugin implements MethodCallHandler {
                 hidden,
                 clearCookies,
                 userAgent,
-                url
+                url,
+                withZoom
         );
         result.success(null);
     }

+ 3 - 1
android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

@@ -68,8 +68,10 @@ class WebviewManager {
         webView.clearFormData();
     }
 
-    void openUrl(boolean withJavascript, boolean clearCache, boolean hidden, boolean clearCookies, String userAgent, String url) {
+    void openUrl(boolean withJavascript, boolean clearCache, boolean hidden, boolean clearCookies, String userAgent, String url, boolean withZoom) {
         webView.getSettings().setJavaScriptEnabled(withJavascript);
+        webView.getSettings().setBuiltInZoomControls(withZoom);
+        webView.getSettings().setSupportZoom(withZoom);
 
         if (clearCache) {
             clearCache();

BIN
example/ios/Flutter/flutter_assets/kernel_blob.bin


BIN
example/ios/Flutter/flutter_assets/platform.dill


+ 2 - 1
example/lib/main.dart

@@ -7,7 +7,7 @@ import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
 const kAndroidUserAgent =
     "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";
 
-String selectedUrl = "https://github.com/dart-flitter/flutter_webview_plugin";
+String selectedUrl = "https://flutter.io";
 
 void main() {
   runApp(new MyApp());
@@ -28,6 +28,7 @@ class MyApp extends StatelessWidget {
               appBar: new AppBar(
                 title: new Text("Widget webview"),
               ),
+              withZoom: true,
             )
       },
     );

+ 7 - 1
ios/Classes/FlutterWebviewPlugin.m

@@ -56,6 +56,7 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     NSDictionary *rect = call.arguments[@"rect"];
     _enableAppScheme = call.arguments[@"enableAppScheme"];
     NSString *userAgent = call.arguments[@"userAgent"];
+    NSNumber *withZoom = call.arguments[@"withZoom"];
     
     //
     if (clearCache != (id)[NSNull null] && [clearCache boolValue]) {
@@ -81,8 +82,13 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     self.webview = [[UIWebView alloc] initWithFrame:rc];
     self.webview.delegate = self;
     
-    if (hidden != (id)[NSNull null] && [hidden boolValue])
+    if (withZoom != (id)[NSNull null] && [withZoom boolValue]) {
+        self.webview.scalesPageToFit = YES;
+    }
+    
+    if (hidden != (id)[NSNull null] && [hidden boolValue]) {
         self.webview.hidden = YES;
+    }
     [self.viewController.view addSubview:self.webview];
     
     [self navigate:call];

+ 4 - 3
lib/src/base.dart

@@ -67,8 +67,7 @@ class FlutterWebviewPlugin {
   /// - [enableAppScheme]: false will enable all schemes, true only for httt/https/about
   ///     android: Not implemented yet
   /// - [userAgent]: set the User-Agent of WebView
-  /// - [title]: title for app/navigation bar
-  /// - [withBackButton]: show back button when fullscreen
+  /// - [withZoom]: enable zoom on webview
   Future<Null> launch(String url,
       {bool withJavascript,
       bool clearCache,
@@ -76,7 +75,8 @@ class FlutterWebviewPlugin {
       bool hidden,
       bool enableAppScheme,
       Rect rect,
-      String userAgent}) async {
+      String userAgent,
+      bool withZoom}) async {
     Map<String, dynamic> args = {
       "url": url,
       "withJavascript": withJavascript ?? true,
@@ -85,6 +85,7 @@ class FlutterWebviewPlugin {
       "clearCookies": clearCookies ?? false,
       "enableAppScheme": enableAppScheme ?? true,
       "userAgent": userAgent,
+      "withZoom": withZoom ?? false
     };
     if (rect != null) {
       args["rect"] = {

+ 9 - 4
lib/src/webview_scaffold.dart

@@ -16,6 +16,7 @@ class WebviewScaffold extends StatefulWidget {
   final bool primary;
   final List<Widget> persistentFooterButtons;
   final Widget bottomNavigationBar;
+  final bool withZoom;
 
   WebviewScaffold(
       {Key key,
@@ -28,7 +29,8 @@ class WebviewScaffold extends StatefulWidget {
       this.userAgent,
       this.primary: true,
       this.persistentFooterButtons,
-      this.bottomNavigationBar})
+      this.bottomNavigationBar,
+      this.withZoom})
       : super(key: key);
 
   @override
@@ -61,7 +63,8 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
           clearCookies: widget.clearCookies,
           enableAppScheme: widget.enableAppScheme,
           userAgent: widget.userAgent,
-          rect: _rect);
+          rect: _rect,
+          withZoom: widget.withZoom);
     } else {
       Rect rect = _buildRect(context);
       if (_rect != rect) {
@@ -91,11 +94,13 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
     num height = mediaQuery.size.height - top;
 
     if (widget.bottomNavigationBar != null) {
-      height -= 56.0; // todo(lejard_h) find a way to determine bottomNavigationBar programmatically
+      height -=
+          56.0; // todo(lejard_h) find a way to determine bottomNavigationBar programmatically
     }
 
     if (widget.persistentFooterButtons != null) {
-      height -= 53.0; // todo(lejard_h) find a way to determine persistentFooterButtons programmatically
+      height -=
+          53.0; // todo(lejard_h) find a way to determine persistentFooterButtons programmatically
     }
 
     return new Rect.fromLTWH(0.0, top, mediaQuery.size.width, height);

+ 1 - 1
pubspec.yaml

@@ -5,7 +5,7 @@ authors:
 - Toufik Zitouni <toufiksapps@gmail.com>
 - Pedia <kpedia@163.com>
 homepage: https://github.com/dart-flitter/flutter_webview_plugin
-version: 0.1.2
+version: 0.1.3
 
 environment:
   sdk: ">=1.8.0 <2.0.0"