Dart中带有google_maps_flutter的GestureDetector [英] GestureDetector with google_maps_flutter in Dart

查看:72
本文介绍了Dart中带有google_maps_flutter的GestureDetector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 google_maps_flutter ,希望在用户在地图上执行手势时执行操作,无论是缩放/倾斜/移动/旋转。但是我无法在 onCameraMoveStarted 属性href = https://pub.dev/documentation/google_maps_flutter/latest/google_maps_flutter/GoogleMap-class.html rel = noreferrer> GoogleMap类,因为它还可以识别引起的非手势用户操作以及程序化的动画(我的应用程序利用了),没有办法(据我所知,请纠正我),以区分它们。

I'm using google_maps_flutter and wish to perform an action when the user performs a gesture on the map, whether it be zoom/tilt/move/rotate. However I'm unable to use the onCameraMoveStarted property in GoogleMap class as it also recognizes non-gesture user action caused as well as programmed animations (which my app utilizes), with no way (as far as I know, please correct me otherwise), to differentiate between them.

因此,我想到了使用flutter小部件 GestureDetector ,将地图包裹在其中,这样我就可以能够根据GestureDetector检测到的手势更改变量,从而间接导致地图更改。

Thus I thought of using the flutter widget GestureDetector, wrapping the map inside it so that I would be able to change variables based on the gestures detected by GestureDetector to cause changes indirectly in the map.

最初没有问题,它充当透明层,可以移动地图/倾斜/旋转d /正常放大。但是,添加通过onPanStart,onPanUpdate或onPanEnd执行的功能后,所有地图均无法通过手势进行交互。我想这全都是被GestureDetector捕获的,但是在将手势传递给孩子时,我无法异步执行额外的任务吗?

No problems initially, it acts as a transparent layer and the map can be moved/tilted/rotated/zoomed normally. However, upon adding a function to execute through onPanStart, onPanUpdate, or onPanEnd all make the map unable to be interacted with through gestures. I suppose it is all being captured by the GestureDetector, but is there no way I can do said extra task asynchronously while passing the gesture along to the child anyway?

结构,btw:

 build(context) {
    return Scaffold(
      body: GestureDetector(
        behavior: HitTestBehavior.deferToChild,
        onPanStart: {...}
        child:
          GoogleMap(...),
      ),
      ...
    );
  }

在此先感谢您的帮助,

推荐答案

我找到了一个可能对您有用的解决方案。

I've found a solution, which might work for you.

class Test extends DragGestureRecognizer {
  Function _test;

  Test(this._test);

  @override
  void resolve(GestureDisposition disposition) {
    super.resolve(disposition);
    this._test();
  }
}

...

return GoogleMap(
        ...
          gestureRecognizers: Set()
            ..add(Factory<DragGestureRecognizer>(() => Test(() {
               if (_focusEnabled) {
                 setState(() {
                   _focusEnabled = false;
                 });
               }
            })),
        );

这会在与地图的每次交互中运行您的函数。
但是我没有找到区分事件的方法。

This runs your function on every interaction with the map. But i did'nt find a way to differentiate between the events.

这篇关于Dart中带有google_maps_flutter的GestureDetector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆