解决多指批注问题

This commit is contained in:
DESKTOP-I3JPKHK\wy 2025-04-25 15:31:23 +08:00
parent 4b65ef1e88
commit 0902c0cd0d
1 changed files with 47 additions and 11 deletions

View File

@ -283,6 +283,35 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
//
static const int timeoutDuration = 300;
void toTimer(ValueNotifier<List<dynamic>> vnHandWritings) {
timer?.cancel();
timer = Timer(const Duration(milliseconds: timeoutDuration), () {
if (_activePointers > 2) {
_activePointers = 0;
if (vnHandWritings.value.last != null) {
vnHandWritings.value.add(null); // 线
sateData.handwritings = vnHandWritings.value; //
}
}
});
}
///
Offset? getLastDrop(List<dynamic> vals, int index) {
Offset? lastDrop;
if (vals.isNotEmpty) {
lastDrop = vals[index] as Offset?;
// if (lastDrop == null) {
// index -= 1;
// if (index > -1) {
// lastDrop = getLastDrop(vals, index);
// }
// }
}
return lastDrop;
}
@override
Widget build(BuildContext context) {
final theMaxHeight = useState<double>(maxHeight);
@ -431,16 +460,17 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
//
_activePointers = _activePointers + 1;
print("+++进入onPointerDown $_activePointers");
timer?.cancel();
timer = Timer(const Duration(milliseconds: timeoutDuration), () {
if (_activePointers > 0) {
_activePointers = 0;
if (vnHandWritings.value.last != null) {
vnHandWritings.value.add(null); // 线
sateData.handwritings = vnHandWritings.value; //
}
}
});
toTimer(vnHandWritings);
// timer?.cancel();
// timer = Timer(const Duration(milliseconds: timeoutDuration), () {
// if (_activePointers > 2) {
// _activePointers = 0;
// if (vnHandWritings.value.last != null) {
// vnHandWritings.value.add(null); // 线
// sateData.handwritings = vnHandWritings.value; //
// }
// }
// });
sateData.panQuestView = true;
},
onPointerUp: (PointerUpEvent details) {
@ -460,7 +490,7 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
onPointerMove: (PointerMoveEvent event) {
print("进入onPointerMove $_activePointers");
if (_activePointers != 1) return;
timer?.cancel();
toTimer(vnHandWritings);
if (!annotationState.pen.value) return;
Offset localPosition = event.localPosition; //
@ -500,6 +530,12 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
(dy - max(0, imageHeightOffsetStart) + ((zoomFile.imageHeightOffsetStart == null || zoomFile.imageHeightOffsetStart! <= 0.1) ? (sateData.zoomOffset?.dy.abs() ?? 0) : 0)) / theScale,
);
///
var lastDrop = getLastDrop(vnHandWritings.value, vnHandWritings.value.length-1);
if (lastDrop != null && ((lastDrop.dx - localPosition.dx).abs() > 40 || (lastDrop.dy - localPosition.dy).abs() > 40)) {
/// X点和上一个x点相差 10
return;
}
// print("最终位置 $localPosition");
vnHandWritings.value = List.from(vnHandWritings.value)..add(localPosition);
sateData.handwritings = vnHandWritings.value;