Home > OS >  list of selected files with file_picker in flutter web
list of selected files with file_picker in flutter web

Time:01-22

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?

CodePudding user response:

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.

CodePudding user response:

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();
  • Related