openCropper method
Future<HLPickerItem>
openCropper(
- String imagePath, {
- HLCropOptions? cropOptions,
- LocalizedImageCropper? localized,
Open image cropper
imagePath
: Path of the image that needs to be cropped
cropOptions
: Configuration options for the cropping functionality: aspectRatio
, aspectRatioPresets
, compressQuality
, compressFormat
localized
: Custom text displayed for the plugin
Returns a HLPickerItem object
Implementation
@override
Future<HLPickerItem> openCropper(
String imagePath, {
HLCropOptions? cropOptions,
LocalizedImageCropper? localized,
}) async {
double? cropCompressQuality = cropOptions?.compressQuality;
assert(cropCompressQuality == null ||
(cropCompressQuality > 0 && cropCompressQuality <= 1));
int? cropWidth = cropOptions?.maxSizeOutput?.maxWidth;
assert(cropWidth == null || cropWidth >= 10);
int? cropHeight = cropOptions?.maxSizeOutput?.maxHeight;
assert(cropHeight == null || cropHeight >= 10);
const defaultPresets = [
CropAspectRatioPreset.original,
CropAspectRatioPreset.square,
CropAspectRatioPreset.ratio3x2,
CropAspectRatioPreset.ratio4x3,
CropAspectRatioPreset.ratio16x9
];
final data = await methodChannel.invokeMethod('openCropper', {
'imagePath': Uri.encodeFull(imagePath),
'ratioX': cropOptions?.aspectRatio?.ratioX,
'ratioY': cropOptions?.aspectRatio?.ratioY,
'aspectRatioPresets': (cropOptions?.aspectRatioPresets ?? defaultPresets)
.map((e) => e.value)
.toList(),
'cropCompressQuality': cropOptions?.compressQuality,
'cropCompressFormat': cropOptions?.compressFormat?.name,
'croppingStyle': cropOptions?.croppingStyle?.name,
'cropMaxWidth': cropWidth,
'cropMaxHeight': cropHeight,
'localized': localized?.toMap(),
});
return HLPickerItem.fromMap(data);
}