使用 flutter_inappwebview 放大 Flutter

问题描述 投票:0回答:2

我使用一个答案中的代码webview_flutter“无法验证证书链”SSL握手失败错误


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);
                   },
                 ),
               ),
             ),
           ]))
   );
 }
}

我尝试使用缩放功能,但 flutter 不知道该选项。我怎样才能将它添加到这个功能中?我需要 Android 和 iOS 的这些功能。

flutter webview package zooming
2个回答
0
投票

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

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

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

希望这有帮助。


0
投票

docs 您可以使用

builtInZoomControls
displayZoomControls
,

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


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

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

注意:您不必使用

supportZoom
,因为默认情况下它是
true

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

© www.soinside.com 2019 - 2024. All rights reserved.