【问题标题】:Zoom in Flutter with flutter_inappwebview使用 flutter_inappwebview 放大 Flutter
【发布时间】:2020-03-27 12:59:45
【问题描述】:

我使用来自一个答案webview_flutter "Failed to validate the certificate chain" SSL handshake failed error的代码


import 'package:flutter/material.dart';

import 'package:flutter_inappwebview/flutter_inappwebview.dart';

Future main() async {
 runApp(new MyApp());
}

class MyApp extends StatefulWidget {
 @override
 _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

 @override
 void initState() {
   super.initState();
 }

 @override
 void dispose() {
   super.dispose();
 }

 @override
 Widget build(BuildContext context) {
   return MaterialApp(
       home: InAppWebViewPage()
   );
 }
} 

class InAppWebViewPage extends StatefulWidget {
 @override
 _InAppWebViewPageState createState() => new _InAppWebViewPageState();
}

class _InAppWebViewPageState extends State<InAppWebViewPage> {
 InAppWebViewController webView;

 @override
 Widget build(BuildContext context) {
   return Scaffold(
       appBar: AppBar(
           title: Text("InAppWebView")
       ),
       body: Container(
           child: Column(children: <Widget>[
             Expanded(
               child: Container(
                 child: InAppWebView(
                   initialUrl: "https://myUrl",
                   initialHeaders: {},
                   initialOptions: InAppWebViewWidgetOptions(
                       inAppWebViewOptions: InAppWebViewOptions(
                         debuggingEnabled: true,
                       ),
                   ),
                   onWebViewCreated: (InAppWebViewController controller) {
                     webView = controller;
                   },
                   onLoadStart: (InAppWebViewController controller, String url) {

                   },
                   onLoadStop: (InAppWebViewController controller, String url) {

                   },
                   onReceivedServerTrustAuthRequest: (InAppWebViewController controller, ServerTrustChallenge challenge) async {
                     return ServerTrustAuthResponse(action: ServerTrustAuthResponseAction.PROCEED);
                   },
                 ),
               ),
             ),
           ]))
   );
 }
}

我尝试使用该功能进行缩放,但颤振不知道该选项。如何将其添加到此功能?我需要 Android 和 iOS 的这些功能。

【问题讨论】:

  • 尝试使用builtInZoomControls displayZoomControls supportZoom

标签: flutter webview package zooming


【解决方案1】:

docs你可以使用builtInZoomControlsdisplayZoomControls

builtInZoomControls:如果 WebView 应该使用其内置缩放机制,则设置为 true。默认值为 false。


displayZoomControls:如果 WebView 在使用内置缩放机制时应显示屏幕缩放控件,则设置为 true。默认值为 false。

InAppWebViewWidgetOptions(
                            inAppWebViewOptions: InAppWebViewOptions(
                              initialUrl: "https://myUrl",
                              builtInZoomControls: true,
                              displayZoomControls: true,
                            ))));

注意:您不必使用supportZoom,因为它默认为true

supportZoom:如果 WebView 不支持使用其屏幕缩放控件和手势进行缩放,则设置为 false。默认值为 true。

【讨论】:

    【解决方案2】:

    您是否尝试在 InAppWebView 中添加不同的缩放选项,如下所示?

    child: InAppWebView(
      initialUrl: "https://myUrl",
      initialHeaders: {},
      initialOptions: ....
      displayZoomControls: true,
      supportZoom: true
    

    您可以在插件的 GitHub 位置了解有关这些选项的更多信息 - https://github.com/pichillilorenzo/flutter_inappwebview

    希望这会有所帮助。

    【讨论】:

    • 我测试了它,但我得到这个错误:“未定义命名参数'displayZoomControls'。” “未定义命名参数 'supportZoom'。”
    • @miwa,这很奇怪。你的pubspec.yaml 中有什么版本的InAppWebView。确保你有flutter_inappwebview: ^2.1.0+1
    • 我使用这个包:flutter_inappbrowser: ^2.0.2 我尝试使用你的包但我无法加载它,我收到一个错误。
    • 是否需要在我的项目中实现androidx才能使用您告诉我使用的方法?
    猜你喜欢
    • 2021-03-10
    • 2023-02-08
    • 2022-10-02
    • 2020-06-16
    • 2020-11-09
    • 1970-01-01
    • 2018-10-19
    • 2021-06-12
    • 2021-10-13
    相关资源
    最近更新 更多