showImageListPicker function

Future<List<ChosenMedia>?> showImageListPicker(
  1. BuildContext context, {
  2. VoidCallback? onPermissionsInitialized,
  3. FilesSelected? onSelected,
  4. FileChanged? onChange,
  5. int maxSelections = 1,
  6. bool crop = true,
  7. bool preemptPermission = true,
  8. MediaSelectFn imageSelector = Choosers.chooseImages,
  9. dynamic extraOptions,
})

Implementation

Future<List<ChosenMedia>?> showImageListPicker(
  BuildContext context, {
  VoidCallback? onPermissionsInitialized,
  FilesSelected? onSelected,
  FileChanged? onChange,
  int maxSelections = 1,
  bool crop = true,
  bool preemptPermission = true,
  // ignore: deprecated_member_use_from_same_package
  MediaSelectFn imageSelector = Choosers.chooseImages,
  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 && images.first.file != null) {
          final imageFile = images.first.file;
          onChange?.call(imageFile, false);
          final cropPt = await ((infoX.isIOS || infoX.isAndroid)
              ? Croppers.cropNative(context, imageFile!)
              : Croppers.cropFallback(context, imageFile!));
          // Upload new image
          onChange?.call(cropPt, true);
          return [ChosenMedia.ofFile(cropPt)];
        } else {
          return images;
        }
      } on NoImagesSelectedException {
        return [];
      }
    case SunnyPermissionStatus.later:
      return [];
  }
  return null;
}