补充提交,修复留白区域笔迹问题

This commit is contained in:
DESKTOP-I3JPKHK\wy 2025-09-15 15:31:46 +08:00
parent 8fd6c57874
commit f638ef23de
1 changed files with 60 additions and 58 deletions

View File

@ -1,6 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:flutter/cupertino.dart' hide TransformationController;
import 'package:flutter/material.dart';
@ -17,6 +15,7 @@ import 'package:making_school_asignment_app/common/utils/cached_network_img.dart
import 'package:making_school_asignment_app/common/utils/toast_utils.dart';
import 'package:making_school_asignment_app/page/global_widget/my_text.dart';
import 'package:making_school_asignment_app/page/home_page/children/homework_review/configuration_files/index.dart';
import 'package:vector_math/vector_math_64.dart' show Vector3, Matrix4;
import 'package:zoom_widget/zoom_widget.dart';
import '../configuration_files/zoom_logic.dart';
@ -299,25 +298,11 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
return -1;
}
int _activePointers = 0;
Timer? timer;
//
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.isNotEmpty && vnHandWritings.value.last != null) {
vnHandWritings.value.add(null); // 线
sateData.handwritings = vnHandWritings.value; //
}
}
});
}
/// build useRef
///
Offset? getLastDrop(List<dynamic> vals, int index) {
@ -338,6 +323,23 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
@override
Widget build(BuildContext context) {
// HookWidget 使
final activePointers = useRef<int>(0);
final timerRef = useRef<Timer?>(null);
void startTimerForHandwriting(ValueNotifier<List<dynamic>> vnHandWritings) {
timerRef.value?.cancel();
timerRef.value = Timer(const Duration(milliseconds: timeoutDuration), () {
if (activePointers.value > 2) {
activePointers.value = 0;
if (vnHandWritings.value.isNotEmpty && vnHandWritings.value.last != null) {
vnHandWritings.value.add(null); // 线
sateData.handwritings = vnHandWritings.value; //
}
}
});
}
final theMaxHeight = useState<double>(maxHeight);
useValueChanged<double, void>(maxHeight, (oldValue, __) => theMaxHeight.value = maxHeight);
@ -477,7 +479,8 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
});
return () {
_activePointers = 0;
activePointers.value = 0;
timerRef.value?.cancel();
eventCancel();
};
}, []);
@ -491,46 +494,37 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
//
//
_activePointers = _activePointers + 1;
activePointers.value = activePointers.value + 1;
///
toTimer(vnHandWritings);
startTimerForHandwriting(vnHandWritings);
sateData.panQuestView = true;
},
onPointerUp: (PointerUpEvent details) {
//
// activePointers--;
// globalPosition = null;
if (_activePointers > 0) {
_activePointers = _activePointers - 1;
if (activePointers.value > 0) {
activePointers.value = activePointers.value - 1;
}
print("---进入onPointerUp $_activePointers");
timer?.cancel();
print("---进入onPointerUp ${activePointers.value}");
timerRef.value?.cancel();
if (!annotationState.pen.value) return;
vnHandWritings.value.add(null); // 线
sateData.handwritings = vnHandWritings.value; //
},
onPointerMove: (PointerMoveEvent event) {
print("进入onPointerMove $_activePointers");
if (_activePointers != 1) return;
toTimer(vnHandWritings);
print("进入onPointerMove ${activePointers.value}");
if (activePointers.value != 1) return;
startTimerForHandwriting(vnHandWritings);
if (!annotationState.pen.value) return;
Offset localPosition = event.localPosition; //
var zoomFile = zoomState.zoomFile.value!;
// var imageHeightOffsetStart = zoomFile.imageHeightOffsetStart??0;
var imageHeightOffsetStart = zoomState.zoomFile.value!.getZoomFileOffsetStart(zoomState.initScale.value ?? 1);
// print("位置:$localPosition; 图片所在位置:$imageHeightOffsetStart");
if (imageHeightOffsetStart == 0) return;
var dy = localPosition.dy;
// print(zoomFile.getZoomFileHeightOffsetEnd(zoomState.initScale.value ?? 1));
if (dy < imageHeightOffsetStart || dy > zoomFile.getZoomFileHeightOffsetEnd(zoomState.initScale.value ?? 1)) {
return; //
}
var theScale = zoomState.initScale.value ?? 1;
// 使
final Matrix4 matrix = logic.zoomController.value; //
final double theScale = matrix.getMaxScaleOnAxis();
// if (theScale != 1) {
// print("PPPPPPPPPPPPPPPPPPPPPPPP ${(zoomFile.imageHeightOffsetStart ?? 0)}");
// localPosition = Offset(localPosition.dx, localPosition.dy + (zoomFile.imageHeightOffsetStart ?? 0));
@ -549,26 +543,36 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
// }
// (dy / theScale) - (max(0, imageHeightOffsetStart) / theScale) + ((sateData.zoomOffset?.dy.abs() ?? 0) / theScale),
var leftOffset = zoomFile.getZoomFileOffsetStartWidth(theScale);
var topOffset = max(0, imageHeightOffsetStart);
// ->
final inv = Matrix4.inverted(matrix);
final v = inv.transform3(Vector3(localPosition.dx, localPosition.dy, 0));
localPosition = Offset(v.x, v.y);
// 使//
final translation = logic.zoomController.value.getTranslation();
final panDx = translation.x;
final panDy = translation.y;
// 0..maxWidth0..actualHeight
if (localPosition.dy < 0 || localPosition.dy > actualHeight) return;
if (localPosition.dx < 0 || localPosition.dx > maxWidth) return;
//
final correctedDx = (localPosition.dx - leftOffset - panDx) / theScale;
final correctedDy = (dy - topOffset - panDy) / theScale;
localPosition = Offset(correctedDx, correctedDy);
///
/// -
/// -
var lastDrop = getLastDrop(vnHandWritings.value, vnHandWritings.value.length - 1);
if (lastDrop != null) {
const double baseJump = 65.0;
final double jumpThreshold = baseJump / theScale;
if ((lastDrop.dx - localPosition.dx).abs() > jumpThreshold ||
(lastDrop.dy - localPosition.dy).abs() > jumpThreshold) {
return; // /
}
}
///
if (Platform.isAndroid) {
var lastDrop = getLastDrop(vnHandWritings.value, vnHandWritings.value.length - 1);
if (lastDrop != null &&
((lastDrop.dx - localPosition.dx).abs() > 65 || (lastDrop.dy - localPosition.dy).abs() > 65)) {
/// X点和上一个x点相差 10
return;
//
if (lastDrop != null) {
const double baseDist = 1.6; //
final double minDist = baseDist / theScale;
final double dx = localPosition.dx - lastDrop.dx;
final double dy = localPosition.dy - lastDrop.dy;
if ((dx * dx + dy * dy) < (minDist * minDist)) {
return; //
}
}
// print("最终位置 $localPosition");
@ -576,9 +580,7 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
sateData.handwritings = vnHandWritings.value;
},
child: Obx(() {
var isPen = annotationState.pen.value;
var showZgtAnnotate = sateData.data.value?.showZgtAnnotate;
return Container(
height: double.infinity,
width: double.infinity,