cropImage method
Future<File?> cropImage ({required File imageFile})
This function is used to crop the image selected by the user.
The function accepts a File
type image and returns File
type of cropped image.
params:
imageFile
: the image file to be cropped.
returns:
Future<File?>
: the image after been cropped.
Implementation
Future<File?> cropImage({required File imageFile}) async {
// try, to crop the image and returns a File with cropped image path.
try {
final CroppedFile? croppedImage = await locator<ImageCropper>().cropImage(
sourcePath: imageFile.path,
aspectRatioPresets: [
CropAspectRatioPreset.square,
CropAspectRatioPreset.original,
],
uiSettings: [
AndroidUiSettings(
toolbarTitle: 'Crop Image',
toolbarColor: const Color(0xff18191A),
toolbarWidgetColor: Colors.white,
backgroundColor: Colors.black,
cropGridColor: Colors.white,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false,
),
IOSUiSettings(
minimumAspectRatio: 1.0,
)
],
);
if (croppedImage != null) {
return File(croppedImage.path);
}
} catch (e) {
print(
"MultiMediaPickerService : Exception occurred while cropping Image",
);
}
return null;
}