pickMultipleImageAndCrop static method
Future<List<String> >
pickMultipleImageAndCrop(
- BuildContext context, {
- required int maxImageCount,
- int? minImageCount,
- List<
CropAspectRatioPreset> aspectRatioPresets = const [CropAspectRatioPreset.square], - CropStyle cropStyle = CropStyle.rectangle,
- required void onError(
- String e
Picks multiple images with cropping functionality and aspect ratio presets.
Returns a list of cropped image paths.
Calls onError
in case of an error.
Implementation
static Future<List<String>> pickMultipleImageAndCrop(
BuildContext context, {
required int maxImageCount,
int? minImageCount,
List<CropAspectRatioPreset> aspectRatioPresets = const [
CropAspectRatioPreset.square,
],
CropStyle cropStyle = CropStyle.rectangle,
required void Function(String e) onError,
}) async {
try {
final picker = hl_image_picker.HLImagePicker();
final pickedFiles = await picker.openPicker(
pickerOptions: hl_image_picker.HLPickerOptions(
maxSelectedAssets: maxImageCount,
minSelectedAssets: minImageCount,
mediaType: hl_image_picker.MediaType.image,
),
cropping: true,
cropOptions: hl_image_picker.HLCropOptions(
aspectRatioPresets: aspectRatioPresets
.map((e) => hlmapAspectRatioPreset(e.name))
.toList(),
croppingStyle: cropStyle == CropStyle.circle
? hl_image_picker.CroppingStyle.circular
: hl_image_picker.CroppingStyle.normal),
);
if (pickedFiles.isEmpty) return [];
final pathList = pickedFiles.map((e) => e.path).toList();
return pathList;
} catch (e) {
onError(e.toString());
return [];
}
}