selectFile method

Future<List<File?>> selectFile()

Implementation

Future<List<File?>> selectFile() async {
  var result = await FilePicker.platform.pickFiles(
    allowMultiple: true,
    type: FileType.custom,
    allowedExtensions: [
      'jpg',
      'jpeg',
      'png',
      'gif',
      'svg',
      'webp',
      'bmp',
      'pdf',
      'doc',
      'docx',
      'xls',
      'xlsx',
      'ppt',
      'pptx',
      'txt',
      'csv',
      'zip',
      'rar',
      '7z',
      'mp3',
      'mp4',
      'wav',
      'avi',
      'flv',
      'mov',
      'wmv',
      'mpg',
      'mpeg',
      'm4v',
      '3gp',
      'mkv',
      'webm',
    ],
  );

  if (result != null) {
    List<File?> files = [];
    for (var file in result.files) {
      files.add(File(file.path ?? ''));
    }
    // File? file = File(result.files.single.path!);
    // log('image gotten');
    return files;
  } else {
    // User canceled the picker
    return [];
  }
}