Closed kreativityapps closed 3 weeks ago
please provide the url in your issue demo
I got the same problem when I continually zoom in and out. I found after calling the method, the rect will have NaN
Rect getFinalDestinationRect() { _reachCropRectEdge = false;
if (screenDestinationRect != null) {
/// scale
final double scaleDelta = totalScale / preTotalScale;
if (scaleDelta != 1.0) {
Offset focalPoint = screenFocalPoint ?? _screenDestinationRect!.center;
focalPoint = Offset(
focalPoint.dx
.clamp(
_screenDestinationRect!.left, _screenDestinationRect!.right)
.toDouble(),
focalPoint.dy
.clamp(
_screenDestinationRect!.top, _screenDestinationRect!.bottom)
.toDouble(),
);
_screenDestinationRect = Rect.fromLTWH(
focalPoint.dx -
(focalPoint.dx - _screenDestinationRect!.left) * scaleDelta,
focalPoint.dy -
(focalPoint.dy - _screenDestinationRect!.top) * scaleDelta,
_screenDestinationRect!.width * scaleDelta,
_screenDestinationRect!.height * scaleDelta);
preTotalScale = totalScale;
delta = Offset.zero;
}
/// move
else {
if (_screenDestinationRect != screenCropRect) {
final bool topSame =
_screenDestinationRect!.topIsSame(screenCropRect!);
final bool leftSame =
_screenDestinationRect!.leftIsSame(screenCropRect!);
final bool bottomSame =
_screenDestinationRect!.bottomIsSame(screenCropRect!);
final bool rightSame =
_screenDestinationRect!.rightIsSame(screenCropRect!);
if (topSame && bottomSame) {
delta = Offset(delta.dx, 0.0);
} else if (leftSame && rightSame) {
delta = Offset(0.0, delta.dy);
}
_screenDestinationRect = _screenDestinationRect!.shift(delta);
}
//we have shift offset, we should clear delta.
delta = Offset.zero;
}
_screenDestinationRect =
computeBoundary(_screenDestinationRect!, screenCropRect!);
// make sure that crop rect is all in image rect.
if (screenCropRect != null) {
Rect rect = screenCropRect!.expandToInclude(_screenDestinationRect!);
if (rect != _screenDestinationRect) {
final bool topSame = rect.topIsSame(screenCropRect!);
final bool leftSame = rect.leftIsSame(screenCropRect!);
final bool bottomSame = rect.bottomIsSame(screenCropRect!);
final bool rightSame = rect.rightIsSame(screenCropRect!);
// make sure that image rect keep same aspect ratio
if (topSame && bottomSame) {
rect = Rect.fromCenter(
center: rect.center,
width: rect.height /
_screenDestinationRect!.height *
_screenDestinationRect!.width,
height: rect.height);
_reachCropRectEdge = true;
} else if (leftSame && rightSame) {
rect = Rect.fromCenter(
center: rect.center,
width: rect.width,
height: rect.width /
_screenDestinationRect!.width *
_screenDestinationRect!.height,
);
_reachCropRectEdge = true;
}
totalScale =
totalScale / (rect.width / _screenDestinationRect!.width);
// init totalScale
if (_rawDestinationRect!.isSame(_rawDestinationRect!)) {
totalScale = 1.0;
}
preTotalScale = totalScale;
_screenDestinationRect = rect;
}
}
} else {
_screenDestinationRect = getRectWithScale(_rawDestinationRect!);
_screenDestinationRect =
computeBoundary(_screenDestinationRect!, screenCropRect!);
}
return _screenDestinationRect!;
}
please update to lastest version
Version
7.0.2
Platforms
dart, Android
Device Model
Samsung A21
flutter info
How to reproduce?
After the image is loaded I zoom in and out. After some time randomly the image jumps and then it turns all white. I can't zoom or drag any more. Trying to get the crop rect now returns: Rect.fromLTRB(NaN, -0.0, NaN, 4000.0) It looks like left and right are NaN.
Logs
Example code (optional)
Contact
No response