filePickerFn function

  1. @deprecated
Future<List<PFile>> filePickerFn(
  1. BuildContext context, {
  2. int? maxSelections = 1,
  3. MediaContentType<Object>? mediaType,
  4. dynamic extraOptions,
})

Implementation

@deprecated
Future<List<PFile>> filePickerFn(BuildContext context,
    {int? maxSelections = 1, MediaContentType? mediaType, extraOptions}) async {
  List<PFile> res;
  if (infoX.isIOS) {
    final isIm =
        await showPicker(context, extraOptions: extraOptions, options: {
      const FileSourceType.files().toOption(),
      const FileSourceType.gallery().toOption(),
    });

    if (isIm == null) {
      return [];
    }

    if (isIm.key == const FileSourceType.files()) {
      final sel = await FilePicker.platform.pickFiles(
        // type: FileType.image,
        type: FileType.custom,
        allowCompression: true,
        // allowedExtensions: mediaType.acceptedFileTypes,
        allowMultiple: maxSelections! > 1,
        withReadStream: true,
        withData: true,
      );
      res = [...?sel?.files];
    } else if (isIm.key == const FileSourceType.gallery()) {
      final sel = await FilePicker.platform.pickFiles(
        type: mediaType == MediaTypes.videoExt
            ? FileType.video
            : mediaType == MediaTypes.imageExt
                ? FileType.image
                : FileType.any,
        allowCompression: true,
        allowMultiple: maxSelections! > 1,
        withReadStream: true,
        withData: true,
      );
      res = [...?sel?.files];
    } else {
      throw "Illegal state";
    }
  } else {
    final sel = await FilePicker.platform.pickFiles(
      // type: FileType.image,
      type: FileType.custom,
      allowCompression: true,
      // allowedExtensions: ["jpg", "png", "jpeg", "gif"],
      allowMultiple: maxSelections! > 1,
      withReadStream: true,
      withData: true,
    );
    res = [...?sel?.files];
  }
  return res;
}