我试图在颤动的Web视图中使用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);
},
);
}),
);
}
}
这是代码的重要组成部分。如果您需要完整的代码,请发表评论。
答案 0 :(得分:1)
我遇到了同样的问题,并且可以通过将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");
})),
),
],
),
),
),
);
}
想知道是否有人遇到类似问题并使其正常工作。