openImageListPicker function
Future<List<PFile?> ?>
openImageListPicker(
- BuildContext context, {
- VoidCallback? onPermissionsInitialized,
- FilesUploaded? onSelected,
- FileChanged? onChange,
- int maxSelections = 1,
- bool crop = true,
- bool preemptPermission = true,
- MediaSelectFn imageSelector = multiImageSelector,
- dynamic extraOptions,
Implementation
@deprecated
Future<List<PFile?>?> openImageListPicker(
BuildContext context, {
VoidCallback? onPermissionsInitialized,
FilesUploaded? onSelected,
FileChanged? onChange,
int maxSelections = 1,
bool crop = true,
bool preemptPermission = true,
MediaSelectFn imageSelector = multiImageSelector,
dynamic extraOptions,
}) async {
final permission = await checkAndRequestPermissions(
context,
title: (intl) => intl!.permissionRequestPhotos,
permission: Permission.photos,
preemptPermission: preemptPermission,
);
switch (permission) {
case SunnyPermissionStatus.rejected:
SunnyHud.error(context, "You haven't granted access to your photos.");
break;
case SunnyPermissionStatus.granted:
try {
onPermissionsInitialized?.call();
final images = await imageSelector(context,
maxSelections: maxSelections, extraOptions: extraOptions);
onSelected?.call(images);
if (crop == true && images.length == 1) {
final imageFile = images.first;
onChange?.call(imageFile, false);
final cropPt = await ((infoX.isIOS || infoX.isAndroid)
? cropNative(context, imageFile!)
: cropFallback(context, imageFile!));
// Upload new image
onChange?.call(cropPt, true);
return [cropPt];
} else {
return images;
}
} on NoImagesSelectedException {
return [];
}
case SunnyPermissionStatus.later:
return [];
}
return null;
}