简体   繁体   中英

list of selected files with file_picker in flutter web

Question from a newbie in Flutter and Dart: With this code I let a user to pick mulitple mp4/avi files in flutter web:

`FilePickerResult? picked = await FilePicker.platform
          .pickFiles(
            allowMultiple: true,
            type: FileType.custom,
            allowedExtensions: ['mp4', 'avi']);`

Now I would need an exression to extrcat the file name (not the path) of the selected files. I was hoping in something like this:

List<File> file_names = picked.files.name.toList();

But this is wrong. Any suggestion?

You can try like this to get List<File>

  List<File> files = picked.paths.map((path) => File(path)).toList();

Also, FilePicker supports picking files from the web so it should not be issue.

And if you're planning to upload files to firebase then make sure you upload in Uint8List format.

You should try map function to extract the name property of each File object in the files list:

List<String> file_names = picked.files.map((file) => file.name).toList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM