getCroppedImage method
Implementation
Future<CroppedFile?> getCroppedImage(ImagePickerType type) async {
final ImagePicker picker = ImagePicker();
return picker
.pickImage(
source: type == ImagePickerType.CAMERA
? ImageSource.camera
: ImageSource.gallery)
.then((img) {
return ImageCropper().cropImage(
sourcePath: img!.path,
maxHeight: size.height.toInt(),
maxWidth: size.width.toInt(),
aspectRatio: CropAspectRatio(
ratioX: size.height.toDouble(), ratioY: size.width.toDouble()),
aspectRatioPresets: [
CropAspectRatioPreset.square,
],
uiSettings: [
AndroidUiSettings(
toolbarTitle: androidSettings?.toolbarTitle,
toolbarColor: androidSettings?.toolbarColor,
statusBarColor: androidSettings?.statusBarColor,
toolbarWidgetColor: androidSettings?.toolbarWidgetColor,
backgroundColor: androidSettings?.backgroundColor,
activeControlsWidgetColor:
androidSettings?.activeControlsWidgetColor,
dimmedLayerColor: androidSettings?.dimmedLayerColor,
cropFrameColor: androidSettings?.cropFrameColor,
cropGridColor: androidSettings?.cropGridColor,
cropFrameStrokeWidth: androidSettings?.cropFrameStrokeWidth,
cropGridRowCount: androidSettings?.cropGridRowCount,
cropGridColumnCount: androidSettings?.cropGridColumnCount,
cropGridStrokeWidth: androidSettings?.cropGridStrokeWidth,
showCropGrid: androidSettings?.showCropGrid,
lockAspectRatio: androidSettings?.lockAspectRatio,
hideBottomControls: androidSettings?.hideBottomControls,
initAspectRatio: androidSettings?.initAspectRatio,
),
IOSUiSettings(
minimumAspectRatio: iosSettings?.minimumAspectRatio,
rectX: iosSettings?.rectX,
rectY: iosSettings?.rectY,
rectWidth: iosSettings?.rectWidth,
rectHeight: iosSettings?.rectHeight,
showActivitySheetOnDone: iosSettings?.showActivitySheetOnDone,
showCancelConfirmationDialog:
iosSettings?.showCancelConfirmationDialog ?? false,
rotateClockwiseButtonHidden:
iosSettings?.rotateClockwiseButtonHidden ?? false,
hidesNavigationBar: iosSettings?.hidesNavigationBar,
rotateButtonsHidden: iosSettings?.rotateButtonsHidden ?? false,
resetButtonHidden: iosSettings?.resetButtonHidden ?? false,
aspectRatioPickerButtonHidden:
iosSettings?.aspectRatioPickerButtonHidden ?? false,
resetAspectRatioEnabled:
iosSettings?.resetAspectRatioEnabled ?? true,
aspectRatioLockDimensionSwapEnabled:
iosSettings?.aspectRatioLockDimensionSwapEnabled ?? false,
aspectRatioLockEnabled:
iosSettings?.aspectRatioLockEnabled ?? false,
title: iosSettings?.title,
doneButtonTitle: iosSettings?.doneButtonTitle,
cancelButtonTitle: iosSettings?.cancelButtonTitle,
)
]);
});
}