skip to Main Content

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?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search