@@ -67,6 +67,9 @@ class CustomImageCrop extends StatefulWidget {
67
67
/// - Stroke Width: 4.0
68
68
final Paint ? pathPaint;
69
69
70
+ /// The radius for rounded corners of the cropping area (only applicable to rounded rectangle shapes).
71
+ final double borderRadius;
72
+
70
73
/// Whether to allow the image to be rotated.
71
74
final bool canRotate;
72
75
@@ -119,6 +122,7 @@ class CustomImageCrop extends StatefulWidget {
119
122
this .canMove = true ,
120
123
this .customProgressIndicator,
121
124
this .ratio,
125
+ this .borderRadius = 0 ,
122
126
Paint ? imagePaintDuringCrop,
123
127
Key ? key,
124
128
}) : this .imagePaintDuringCrop = imagePaintDuringCrop ??
@@ -202,7 +206,8 @@ class _CustomImageCropState extends State<CustomImageCrop>
202
206
screenWidth: _width,
203
207
);
204
208
final scale = data.scale * cropParams.additionalScale;
205
- _path = _getPath (cropParams.cropSizeToPaint, _width, _height);
209
+ _path = _getPath (
210
+ cropParams.cropSizeToPaint, _width, _height, widget.borderRadius);
206
211
return XGestureDetector (
207
212
onMoveStart: onMoveStart,
208
213
onMoveUpdate: onMoveUpdate,
@@ -279,7 +284,8 @@ class _CustomImageCropState extends State<CustomImageCrop>
279
284
addTransition (CropImageData (x: event.delta.dx, y: event.delta.dy));
280
285
}
281
286
282
- Path _getPath (double cropWidth, double width, double height) {
287
+ Path _getPath (
288
+ double cropWidth, double width, double height, double borderRadius) {
283
289
switch (widget.shape) {
284
290
case CustomCropShape .Circle :
285
291
return Path ()
@@ -291,20 +297,26 @@ class _CustomImageCropState extends State<CustomImageCrop>
291
297
);
292
298
case CustomCropShape .Ratio :
293
299
return Path ()
294
- ..addRect (
295
- Rect .fromCenter (
296
- center: Offset (width / 2 , height / 2 ),
297
- width: cropWidth,
298
- height: cropWidth * widget.ratio! .height / widget.ratio! .width,
300
+ ..addRRect (
301
+ RRect .fromRectAndRadius (
302
+ Rect .fromCenter (
303
+ center: Offset (width / 2 , height / 2 ),
304
+ width: cropWidth,
305
+ height: cropWidth * widget.ratio! .height / widget.ratio! .width,
306
+ ),
307
+ Radius .circular (borderRadius),
299
308
),
300
309
);
301
310
default :
302
311
return Path ()
303
- ..addRect (
304
- Rect .fromCenter (
305
- center: Offset (width / 2 , height / 2 ),
306
- width: cropWidth,
307
- height: cropWidth,
312
+ ..addRRect (
313
+ RRect .fromRectAndRadius (
314
+ Rect .fromCenter (
315
+ center: Offset (width / 2 , height / 2 ),
316
+ width: cropWidth,
317
+ height: cropWidth,
318
+ ),
319
+ Radius .circular (borderRadius),
308
320
),
309
321
);
310
322
}
@@ -328,8 +340,8 @@ class _CustomImageCropState extends State<CustomImageCrop>
328
340
screenWidth: _width,
329
341
dataScale: data.scale,
330
342
);
331
- final clipPath = Path .from (_getPath (
332
- onCropParams.cropSize, onCropParams.cropSize, onCropParams.cropSize ));
343
+ final clipPath = Path .from (_getPath (onCropParams.cropSize,
344
+ onCropParams.cropSize, onCropParams.cropSize, widget.borderRadius ));
333
345
final matrix4Image = Matrix4 .diagonal3 (vector_math.Vector3 .all (1 ))
334
346
..translate (
335
347
onCropParams.translateScale * data.x + onCropParams.cropSize / 2 ,
0 commit comments