在 webview_flutter 中启用捏合和缩放,在其中添加代码片段 [this.webView.getSettings().setBuiltInZoomControls(true);]

enable pinch and zoom in webview_flutter, where to add code snippet [this.webView.getSettings().setBuiltInZoomControls(true);]

想要缩放到 webview_flutter

(我知道 flutter_webview_plugin 可以做到,但出于其他原因我想坚持使用 flutter_webview。)

Zoom support #34

Flutter: how to enable gestures in a web view?

Flutter webview plugin - enable pinch zoom

他们都提到了

this.webView.getSettings().setBuiltInZoomControls(true);

this.webView.getSettings().setSupportZoom(true); to allow pinch/zoom.

原谅我的愚蠢,我找不到添加这段代码的地方,请帮忙。

你尝试缩放 属性 吗?这个问题两年前问过,用 zoom 属性.

修复

还有 this.webView.getSettings 在本机库代码中。如果你要用,首先会在java native code 中写Webview manager 然后叫你manager。

多看源代码库(这个管理器class有setSupportZoom & setBuiltInZoomControls,只用zoom 属性设置为true)WebviewManager Source

下载此存储库:https://github.com/FisherWL/plugins/tree/add-zoom (thanks FisherWL)

将包内的文件夹 webview_flutter 复制到您的项目根文件夹,

然后在 pubspec.yaml 上引用文件夹,如下所示:

  webview_flutter:
    path: ./webview_flutter

在webview_flutter包中有一种放大或缩小的方法,但我认为它不是很有效。尽管如此,它还是有效的✌。

import 'package:webview_flutter/webview_flutter.dart';
import 'package:zoom_widget/zoom_widget.dart';

Size size = MediaQuery.of(context).size;
Zoom(
maxZoomWidth: size.width * 3,
maxZoomHeight: size.height * 3,
child: WebView(
   initialUrl: myUrl),
),

根据您的需要,您可以修改 ZoonWidth 和 height 的最大值