Skip to content

Commit 508cf54

Browse files
committed
added clipShapeOnCrop param
1 parent 4cffa2b commit 508cf54

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

lib/src/widgets/custom_image_crop_widget.dart

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class CustomImageCrop extends StatefulWidget {
8787
/// This widget is used to specify a custom progress indicator
8888
final Widget? customProgressIndicator;
8989

90+
/// Whether to clip the area outside of the path when cropping
91+
/// By default, the value is `true`
92+
final bool clipShapeOnCrop;
93+
9094
/// A custom image cropper widget
9195
///
9296
/// Uses a `CustomImageCropController` to crop the image.
@@ -116,6 +120,7 @@ class CustomImageCrop extends StatefulWidget {
116120
this.canRotate = true,
117121
this.canScale = true,
118122
this.canMove = true,
123+
this.clipShapeOnCrop = true,
119124
this.customProgressIndicator,
120125
this.ratio,
121126
this.borderRadius = 0,
@@ -208,8 +213,8 @@ class _CustomImageCropState extends State<CustomImageCrop>
208213
screenWidth: _width,
209214
);
210215
final scale = data.scale * cropParams.additionalScale;
211-
_path = _getPath(
212-
cropParams.cropSizeToPaint, _width, _height, widget.borderRadius);
216+
_path = _getPath(cropParams.cropSizeToPaint, _width, _height,
217+
widget.borderRadius, true);
213218
return XGestureDetector(
214219
onMoveStart: onMoveStart,
215220
onMoveUpdate: onMoveUpdate,
@@ -286,8 +291,19 @@ class _CustomImageCropState extends State<CustomImageCrop>
286291
addTransition(CropImageData(x: event.delta.dx, y: event.delta.dy));
287292
}
288293

289-
Path _getPath(
290-
double cropWidth, double width, double height, double borderRadius) {
294+
Path _getPath(double cropWidth, double width, double height,
295+
double borderRadius, bool clip) {
296+
if (!clip) {
297+
return Path()
298+
..addRect(
299+
Rect.fromCenter(
300+
center: Offset(width / 2, height / 2),
301+
width: cropWidth,
302+
height: cropWidth,
303+
),
304+
);
305+
}
306+
291307
switch (widget.shape) {
292308
case CustomCropShape.Circle:
293309
return Path()
@@ -342,8 +358,13 @@ class _CustomImageCropState extends State<CustomImageCrop>
342358
screenWidth: _width,
343359
dataScale: data.scale,
344360
);
345-
final clipPath = Path.from(_getPath(onCropParams.cropSize,
346-
onCropParams.cropSize, onCropParams.cropSize, widget.borderRadius));
361+
final clipPath = Path.from(_getPath(
362+
onCropParams.cropSize,
363+
onCropParams.cropSize,
364+
onCropParams.cropSize,
365+
widget.borderRadius,
366+
widget.clipShapeOnCrop,
367+
));
347368
final matrix4Image = Matrix4.diagonal3(vector_math.Vector3.all(1))
348369
..translate(
349370
onCropParams.translateScale * data.x + onCropParams.cropSize / 2,

0 commit comments

Comments
 (0)