pickMultipleFiles method

Future<List<File>> pickMultipleFiles({
  1. List<String>? allowedExtensions,
  2. FileType type = fp.FileType.any,
  3. bool allowCompression = true,
  4. String? dialogTitle,
})

Implementation

Future<List<File>> pickMultipleFiles({
  List<String>? allowedExtensions,
  fp.FileType type = fp.FileType.any,
  bool allowCompression = true,
  String? dialogTitle,
}) async {
  bool hasPermission = await _checkStoragePermission();
  if (!hasPermission) return [];

  try {
    final result = await fp.FilePicker.platform.pickFiles(
      type: allowedExtensions != null ? fp.FileType.custom : type,
      allowedExtensions: allowedExtensions,
      allowCompression: allowCompression,
      allowMultiple: true,
      dialogTitle: dialogTitle,
      withData: false,
      withReadStream: true,
    );

    if (result != null && result.files.isNotEmpty) {
      final files = result.files
          .where((file) => file.path != null)
          .map((file) => File(file.path!))
          .toList();
      return files;
    }
  } catch (e) {
    print('Error picking files: $e');
  }
  return [];
}