diff --git a/lib/src/widget/crop.dart b/lib/src/widget/crop.dart index 0998c65..c703597 100644 --- a/lib/src/widget/crop.dart +++ b/lib/src/widget/crop.dart @@ -20,7 +20,12 @@ typedef CornerDotBuilder = Widget Function( typedef CroppingRectBuilder = ViewportBasedRect Function( ViewportBasedRect viewportRect, - ViewportBasedRect imageRect, + ImageBasedRect imageRect, +); + +typedef OnMovedCallback = void Function( + ViewportBasedRect viewportRect, + ImageBasedRect imageRect, ); enum CropStatus { nothing, loading, ready, cropping } @@ -72,7 +77,7 @@ class Crop extends StatelessWidget { final CropController? controller; /// Callback called when cropping rect changes for any reasons. - final ValueChanged? onMoved; + final OnMovedCallback? onMoved; /// Callback called when status of Crop widget is changed. /// @@ -208,7 +213,7 @@ class _CropEditor extends StatefulWidget { final ImageBasedRect? initialArea; final bool withCircleUi; final CropController? controller; - final ValueChanged? onMoved; + final OnMovedCallback? onMoved; final ValueChanged? onStatusChanged; final Color? maskColor; final Color baseColor; @@ -279,7 +284,18 @@ class _CropEditorState extends State<_CropEditor> { late ViewportBasedRect _cropRect; set cropRect(ViewportBasedRect newRect) { setState(() => _cropRect = newRect); - widget.onMoved?.call(_cropRect); + + final screenSizeRatio = calculator.screenSizeRatio( + _parsedImageDetail!, + _viewportSize, + ); + final imageBaseRect = Rect.fromLTWH( + (_cropRect.left - _imageRect.left) * screenSizeRatio / _scale, + (_cropRect.top - _imageRect.top) * screenSizeRatio / _scale, + _cropRect.width * screenSizeRatio / _scale, + _cropRect.height * screenSizeRatio / _scale, + ); + widget.onMoved?.call(_cropRect, imageBaseRect); } bool get _isImageLoading => _lastComputed != null; diff --git a/test/widget/controller_test.dart b/test/widget/controller_test.dart index 130fddd..46c85da 100644 --- a/test/widget/controller_test.dart +++ b/test/widget/controller_test.dart @@ -92,7 +92,7 @@ void main() { image: testLandscapeImage, controller: controller, onCropped: (value) {}, - onMoved: (rect) { + onMoved: (rect, _) { initialRect ??= rect; lastRect = rect; }, @@ -126,7 +126,7 @@ void main() { controller: controller, aspectRatio: 1, onCropped: (value) {}, - onMoved: (rect) { + onMoved: (rect, _) { initialRect ??= rect; lastRect = rect; }, @@ -161,7 +161,7 @@ void main() { controller: controller, aspectRatio: 1, onCropped: (value) {}, - onMoved: (rect) => lastRect = rect, + onMoved: (rect, _) => lastRect = rect, ), ); @@ -195,7 +195,7 @@ void main() { controller: controller, aspectRatio: 1, onCropped: (value) {}, - onMoved: (rect) => lastRect = rect, + onMoved: (rect, _) => lastRect = rect, ), ); @@ -233,7 +233,7 @@ void main() { controller: controller, aspectRatio: 1, onCropped: (value) {}, - onMoved: (rect) => lastRect = rect, + onMoved: (rect, _) => lastRect = rect, ), ); diff --git a/test/widget/crop_test.dart b/test/widget/crop_test.dart index 13f99ee..9281b80 100644 --- a/test/widget/crop_test.dart +++ b/test/widget/crop_test.dart @@ -161,7 +161,7 @@ void main() { Crop( image: testImage, onCropped: (value) {}, - onMoved: (value) { + onMoved: (_, __) { if (!completer.isCompleted) { completer.complete(); } @@ -196,7 +196,7 @@ void main() { Crop( image: testImage, onCropped: (value) {}, - onMoved: (value) { + onMoved: (_, __) { if (!completer.isCompleted) { completer.complete(); } @@ -234,7 +234,7 @@ void main() { Crop( image: testImage, onCropped: (value) {}, - onMoved: (value) { + onMoved: (_, __) { if (!completer.isCompleted) { completer.complete(); } @@ -270,7 +270,7 @@ void main() { Crop( image: testImage, onCropped: (value) {}, - onMoved: (value) { + onMoved: (_, __) { calledCount++; }, fixCropRect: true,