我正在尝试制作一个与 Google 日历周视图完全相同的小部件。这意味着
\n这是一个例子。
\n这是示例的GitHub 存储库。
\n为了简单起见,我想只关注可能的垂直滚动,我可以自己添加其余的。
\n问题是 PinchToZoom 非常不可靠,即使我进行捏缩放,列表也会开始滚动。为什么会发生这种情况?我做了一些研究并找到了这篇文章。
\n它基本上描述了我的问题的简化版本,即两个手势检测器竞争。解决方案是 RawGestureDetector。我自己写的:
\nclass PinchToZoomGestureRecognizer extends OneSequenceGestureRecognizer {\n final void Function() onScaleStart;\n final void Function() onScaleUpdate;\n final void Function() onScaleEnd;\n\n PinchToZoomGestureRecognizer({\n required this.onScaleStart,\n required this.onScaleUpdate,\n required this.onScaleEnd,\n });\n\n @override\n String get debugDescription => \'$runtimeType\';\n\n Map<int, Offset> pointerPositionMap = {};\n\n @override\n void addAllowedPointer(PointerEvent event) {\n startTrackingPointer(event.pointer);\n pointerPositionMap[event.pointer] = event.position;\n if (pointerPositionMap.length >= 2) {\n resolve(GestureDisposition.accepted);\n …Run Code Online (Sandbox Code Playgroud)