gpt4 book ai didi

flutter - tapgesturerecognizer无法在 flutter 的webview中工作

转载 作者:行者123 更新时间:2023-12-03 03:12:22 24 4
gpt4 key购买 nike

我尝试在 flutter 的Web View 中使用GestureRecognizer来缩小Double pinch,但是它不起作用。如果您有任何解决方案,请帮助我

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';

void main()=>runApp(WebView());

class WebView extends StatefulWidget {
@override
_WebViewState createState() => _WebViewState();
}

class _WebViewState extends State<WebView> {
final Completer<WebViewController> _controller =
Completer<WebViewController>();

@override
Widget build(BuildContext context) {
return Scaffold(


body: Builder(builder: (BuildContext context) {
return WebView(
key: UniqueKey(),
gestureRecognizers:
Set()..add(Factory<TapGestureRecognizer>(() => TapGestureRecognizer(),)),//ZOOM WEBVIEW

initialUrl:
'https://stackoverflow.com/questions/',

javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
);
}),

);
}
}


这是代码的重要部分。如果您需要完整的代码,请发表评论。

最佳答案

我遇到了同样的问题,并且可以通过将TapGestureRecognizer包装到WebView中并在其中加上GestureDetector来使onTap()工作。除了我不知道为什么它起作用。

@override
Widget build(BuildContext context) {
return Scaffold(
body: GestureDetector(
onTap: () {
print("This one doesn't print");
},
child: Container(
child: Stack(
children: <Widget>[
WebView(
initialUrl:
'example.com',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
gestureRecognizers: Set()
..add(
Factory<TapGestureRecognizer>(() => TapGestureRecognizer()
..onTapDown = (tap) {
print("This one prints");
})),
),
],
),
),
),
);
}

想知道是否有人遇到过类似的问题并使它正常工作。

关于flutter - tapgesturerecognizer无法在 flutter 的webview中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58811375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com