onScaleUpdate method
Implementation
void onScaleUpdate(ScaleUpdateDetails details) {
if (details.pointerCount < 2 || details.rotation == 0) {
//滑动
if (_dragFirst) {
_dragFirst = false;
ScaleStartDetails fd = _dragDetails!;
double dx = details.focalPoint.dx - fd.focalPoint.dx;
double dy = details.focalPoint.dy - fd.focalPoint.dy;
double at = (atan2(dy, dx) * 180 / pi).abs();
NormalEvent eventH = NormalEvent(details.localFocalPoint, null);
NormalEvent eventV = NormalEvent(details.localFocalPoint, null);
_dragDirection = at < 45 ? Direction.horizontal : Direction.vertical;
Set<ChartGesture> removeList = {};
for (var ele in _dragNodeList) {
if (!ele.isInArea(details.focalPoint)) {
removeList.add(ele);
} else {
if (_dragDirection == Direction.horizontal) {
ele.horizontalDragStart?.call(eventH);
} else {
ele.verticalDragStart?.call(eventV);
}
}
}
if (removeList.isNotEmpty) {
_dragNodeList.removeAll(removeList);
}
} else {
NormalEvent eventH = NormalEvent(details.localFocalPoint, null);
NormalEvent eventV = NormalEvent(details.localFocalPoint, null);
Set<ChartGesture> removeList = {};
for (var ele in _dragNodeList) {
if (!ele.isInArea(details.focalPoint)) {
removeList.add(ele);
if (_dragDirection == Direction.horizontal) {
ele.horizontalDragCancel?.call();
} else {
ele.verticalDragCancel?.call();
}
} else {
if (_dragDirection == Direction.horizontal) {
ele.horizontalDragMove?.call(eventH);
} else {
ele.verticalDragMove?.call(eventV);
}
}
}
if (removeList.isNotEmpty) {
_dragNodeList.removeAll(removeList);
}
}
return;
}
///缩放
Set<ChartGesture> removeSet = {};
ScaleEvent motionEvent = ScaleEvent(
details.scale,
details.horizontalScale,
details.verticalScale,
details.rotation,
details.localFocalPoint,
null);
for (var ele in _scaleNodeList) {
if (!ele.isInArea(motionEvent.globalPosition)) {
removeSet.add(ele);
ele.scaleCancel?.call();
} else {
ele.scaleUpdate?.call(motionEvent);
}
}
if (removeSet.isNotEmpty) {
_scaleNodeList.removeAll(removeSet);
}
}