openImageListPicker function

  1. @deprecated
Future<List<PFile?>?> openImageListPicker(
  1. BuildContext context, {
  2. VoidCallback? onPermissionsInitialized,
  3. FilesUploaded? onSelected,
  4. FileChanged? onChange,
  5. int maxSelections = 1,
  6. bool crop = true,
  7. bool preemptPermission = true,
  8. MediaSelectFn imageSelector = multiImageSelector,
  9. 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;
}