google-maps - Dart 中带有 google_maps_flutter 的 GestureDetector
问题描述
我正在使用google_maps_flutter并希望在用户在地图上执行手势时执行操作,无论是缩放/倾斜/移动/旋转。但是我无法在GoogleMap 类中使用onCameraMoveStarted属性,因为它还可以识别非手势用户操作以及编程动画(我的应用程序使用),没有办法(据我所知,请更正我) , 来区分它们。
因此,我想到了使用颤振小部件GestureDetector,将地图包裹在其中,这样我就可以根据 GestureDetector 检测到的手势更改变量,从而间接导致地图发生变化。
最初没有问题,它充当透明层,并且可以正常移动/倾斜/旋转/缩放地图。但是,在添加了通过 onPanStart、onPanUpdate 或 onPanEnd 执行的函数后,都会使地图无法通过手势进行交互。我想这一切都被 GestureDetector 捕获了,但是我有没有办法在将手势传递给孩子的同时异步执行额外的任务?
这是结构,顺便说一句:
build(context) {
return Scaffold(
body: GestureDetector(
behavior: HitTestBehavior.deferToChild,
onPanStart: {...}
child:
GoogleMap(...),
),
...
);
}
在此先感谢,非常感谢任何帮助。
解决方案
我找到了一个可能对你有用的解决方案。
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;
});
}
})),
);
这会在与地图的每次交互中运行您的函数。但我没有找到区分事件的方法。
推荐阅读
- typo3 - TYPO3 CASE with Templavoilà FCE id
- java - 如何通过方法引用访问对象对象内部的方法
- node.js - Mongodb Shell 命令执行以通过 nodejs 删除集合
- java - 如何在 Assets 文件夹中升级 SQLite 数据库
- java - Spring Data JPA - 如何缓存包含在许多其他实体中的实体
- java - 从 2 个列表中过滤并使用 java8 获取匹配的记录
- android - 如何使用融合位置客户端仅获得一个位置?
- html - 从屏幕边缘到容器边缘的伪元素
- r - 在闪亮的应用程序中编辑 rhandsontable 后更新 selectInput() 选项
- php - 无法从 PHP WSock32 DLL 连接到 Teradata