@@ -87,6 +87,10 @@ class CustomImageCrop extends StatefulWidget {
87
87
/// This widget is used to specify a custom progress indicator
88
88
final Widget ? customProgressIndicator;
89
89
90
+ /// Whether to clip the area outside of the path when cropping
91
+ /// By default, the value is `true`
92
+ final bool clipShapeOnCrop;
93
+
90
94
/// A custom image cropper widget
91
95
///
92
96
/// Uses a `CustomImageCropController` to crop the image.
@@ -116,6 +120,7 @@ class CustomImageCrop extends StatefulWidget {
116
120
this .canRotate = true ,
117
121
this .canScale = true ,
118
122
this .canMove = true ,
123
+ this .clipShapeOnCrop = true ,
119
124
this .customProgressIndicator,
120
125
this .ratio,
121
126
this .borderRadius = 0 ,
@@ -208,8 +213,8 @@ class _CustomImageCropState extends State<CustomImageCrop>
208
213
screenWidth: _width,
209
214
);
210
215
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 );
213
218
return XGestureDetector (
214
219
onMoveStart: onMoveStart,
215
220
onMoveUpdate: onMoveUpdate,
@@ -286,8 +291,19 @@ class _CustomImageCropState extends State<CustomImageCrop>
286
291
addTransition (CropImageData (x: event.delta.dx, y: event.delta.dy));
287
292
}
288
293
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
+
291
307
switch (widget.shape) {
292
308
case CustomCropShape .Circle :
293
309
return Path ()
@@ -342,8 +358,13 @@ class _CustomImageCropState extends State<CustomImageCrop>
342
358
screenWidth: _width,
343
359
dataScale: data.scale,
344
360
);
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
+ ));
347
368
final matrix4Image = Matrix4 .diagonal3 (vector_math.Vector3 .all (1 ))
348
369
..translate (
349
370
onCropParams.translateScale * data.x + onCropParams.cropSize / 2 ,
0 commit comments