tapgesturerecognizer无法在抖动的Webview中工作

时间:2019-11-12 03:00:49

标签: flutter dart

我试图在颤动的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);
          },
        );
      }),

    );
  }
}

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

1 个答案:

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

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