fix desktop scroll/pan/zoom
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'filament_controller.dart';
|
import 'filament_controller.dart';
|
||||||
import 'filament_widget.dart';
|
import 'filament_widget.dart';
|
||||||
@@ -74,39 +77,70 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
|
|||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer? _scrollTimer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Stack(children: [
|
return Stack(children: [
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: GestureDetector(
|
child: Listener(
|
||||||
behavior: HitTestBehavior.opaque,
|
onPointerSignal: (pointerSignal) async {
|
||||||
onScaleStart: (d) async {
|
if (pointerSignal is PointerScrollEvent) {
|
||||||
if (d.pointerCount == 2) {
|
_scrollTimer?.cancel();
|
||||||
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 {
|
} else {
|
||||||
await _functionStart(d.focalPoint.dx, d.focalPoint.dy);
|
print(pointerSignal);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onScaleEnd: (d) async {
|
onPointerPanZoomStart: (pzs) {
|
||||||
if (d.pointerCount == 2) {
|
print(pzs);
|
||||||
_lastScale = 0;
|
|
||||||
await widget.controller.zoomEnd();
|
|
||||||
} else {
|
|
||||||
await _functionEnd();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onScaleUpdate: (d) async {
|
onPointerDown: (d) async {
|
||||||
if (d.pointerCount == 2) {
|
await _functionStart(d.localPosition.dx, d.localPosition.dy);
|
||||||
if (_lastScale != 0) {
|
|
||||||
await widget.controller
|
|
||||||
.zoomUpdate(100 * (_lastScale - d.scale));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await _functionUpdate(d.focalPoint.dx, d.focalPoint.dy);
|
|
||||||
}
|
|
||||||
_lastScale = d.scale;
|
|
||||||
},
|
},
|
||||||
|
onPointerMove: (d) async {
|
||||||
|
await _functionUpdate(d.localPosition.dx, d.localPosition.dy);
|
||||||
|
},
|
||||||
|
onPointerUp: (d) async {
|
||||||
|
await _functionEnd();
|
||||||
|
},
|
||||||
|
// on
|
||||||
|
// 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)),
|
child: widget.child)),
|
||||||
widget.showControls
|
widget.showControls
|
||||||
? Align(
|
? Align(
|
||||||
|
|||||||
Reference in New Issue
Block a user