fix pinch zoom on mobile

This commit is contained in:
Nick Fisher
2022-12-13 10:56:22 +08:00
parent fbc2823bfd
commit 35f2b1a0e2

View File

@@ -83,65 +83,61 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Stack(children: [ return Stack(children: [
Positioned.fill( Positioned.fill(
child: Listener( // pinch zoom on mobile
onPointerSignal: (pointerSignal) async { // couldn't find any equivalent for pointerCount in Listener so we use two widgets:
if (pointerSignal is PointerScrollEvent) { // - outer is a GestureDetector only for pinch zoom
_scrollTimer?.cancel(); // - inner is a Listener for all other gestures
child: GestureDetector(
onScaleStart: (d) async {
if (d.pointerCount == 2) {
await widget.controller.zoomEnd();
await widget.controller.zoomBegin(); await widget.controller.zoomBegin();
await widget.controller.zoomUpdate(
pointerSignal.scrollDelta.dy > 0 ? 100 : -100);
_scrollTimer = Timer(Duration(milliseconds: 100), () {
widget.controller.zoomEnd();
_scrollTimer = null;
});
} else {
print(pointerSignal);
} }
}, },
onPointerPanZoomStart: (pzs) { onScaleEnd: (d) async {
print(pzs); if (d.pointerCount == 2) {
_lastScale = 0;
await widget.controller.zoomEnd();
}
}, },
onPointerDown: (d) async { onScaleUpdate: (d) async {
await _functionStart(d.localPosition.dx, d.localPosition.dy); if (d.pointerCount == 2) {
if (_lastScale != 0) {
await widget.controller
.zoomUpdate(100 * (_lastScale - d.scale));
}
}
_lastScale = d.scale;
}, },
onPointerMove: (d) async { child: Listener(
await _functionUpdate(d.localPosition.dx, d.localPosition.dy); onPointerSignal: (pointerSignal) async {
}, // scroll-wheel zoom on desktop
onPointerUp: (d) async { if (pointerSignal is PointerScrollEvent) {
await _functionEnd(); _scrollTimer?.cancel();
}, await widget.controller.zoomBegin();
// on await widget.controller.zoomUpdate(
// onScaleStart: (d) async { pointerSignal.scrollDelta.dy > 0 ? 100 : -100);
// print("SCALE START"); _scrollTimer = Timer(Duration(milliseconds: 100), () {
// if (d.pointerCount == 2) { widget.controller.zoomEnd();
// await widget.controller.zoomEnd(); _scrollTimer = null;
// await widget.controller.zoomBegin(); });
// } else { } else {
// await _functionStart(d.focalPoint.dx, d.focalPoint.dy); print(pointerSignal);
// } }
// }, },
// onScaleEnd: (d) async { onPointerPanZoomStart: (pzs) {},
// print("SCALE END"); onPointerDown: (d) async {
await _functionStart(
// if (d.pointerCount == 2) { d.localPosition.dx, d.localPosition.dy);
// _lastScale = 0; },
// await widget.controller.zoomEnd(); onPointerMove: (d) async {
// } else { await _functionUpdate(
// await _functionEnd(); d.localPosition.dx, d.localPosition.dy);
// } },
// }, onPointerUp: (d) async {
// onScaleUpdate: (d) async { await _functionEnd();
// if (d.pointerCount == 2) { },
// if (_lastScale != 0) { child: widget.child))),
// await widget.controller
// .zoomUpdate(100 * (_lastScale - d.scale));
// }
// } else {
// await _functionUpdate(d.focalPoint.dx, d.focalPoint.dy);
// }
// _lastScale = d.scale;
// },
child: widget.child)),
widget.showControls widget.showControls
? Align( ? Align(
alignment: Alignment.bottomRight, alignment: Alignment.bottomRight,