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,8 +83,35 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Stack(children: [ return Stack(children: [
Positioned.fill( Positioned.fill(
// pinch zoom on mobile
// couldn't find any equivalent for pointerCount in Listener so we use two widgets:
// - outer is a GestureDetector only for pinch zoom
// - 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();
}
},
onScaleEnd: (d) async {
if (d.pointerCount == 2) {
_lastScale = 0;
await widget.controller.zoomEnd();
}
},
onScaleUpdate: (d) async {
if (d.pointerCount == 2) {
if (_lastScale != 0) {
await widget.controller
.zoomUpdate(100 * (_lastScale - d.scale));
}
}
_lastScale = d.scale;
},
child: Listener( child: Listener(
onPointerSignal: (pointerSignal) async { onPointerSignal: (pointerSignal) async {
// scroll-wheel zoom on desktop
if (pointerSignal is PointerScrollEvent) { if (pointerSignal is PointerScrollEvent) {
_scrollTimer?.cancel(); _scrollTimer?.cancel();
await widget.controller.zoomBegin(); await widget.controller.zoomBegin();
@@ -98,50 +125,19 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
print(pointerSignal); print(pointerSignal);
} }
}, },
onPointerPanZoomStart: (pzs) { onPointerPanZoomStart: (pzs) {},
print(pzs);
},
onPointerDown: (d) async { onPointerDown: (d) async {
await _functionStart(d.localPosition.dx, d.localPosition.dy); await _functionStart(
d.localPosition.dx, d.localPosition.dy);
}, },
onPointerMove: (d) async { onPointerMove: (d) async {
await _functionUpdate(d.localPosition.dx, d.localPosition.dy); await _functionUpdate(
d.localPosition.dx, d.localPosition.dy);
}, },
onPointerUp: (d) async { onPointerUp: (d) async {
await _functionEnd(); await _functionEnd();
}, },
// on child: widget.child))),
// onScaleStart: (d) async {
// print("SCALE START");
// if (d.pointerCount == 2) {
// await widget.controller.zoomEnd();
// await widget.controller.zoomBegin();
// } else {
// await _functionStart(d.focalPoint.dx, d.focalPoint.dy);
// }
// },
// onScaleEnd: (d) async {
// print("SCALE END");
// if (d.pointerCount == 2) {
// _lastScale = 0;
// await widget.controller.zoomEnd();
// } else {
// await _functionEnd();
// }
// },
// onScaleUpdate: (d) async {
// if (d.pointerCount == 2) {
// if (_lastScale != 0) {
// 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,