Flutter-选择附件,图片,视频。file_picker

仅供参考:

引入插件:

file_picker: ^1.3.8

按照返回值,分了三组:

// Single file path
String filePath;
第一组:返回文件地址
//选择任何文件
filePath = await FilePicker.getFilePath(type: FileType.ANY); // will let you pick one file path, from all extensions
//选择指定后缀的文件,但是这个不很准确,我测试的“doc”,但是实际上出现了很多后缀不是doc的文件   
filePath = await FilePicker.getFilePath(type: FileType.CUSTOM, fileExtension: 'svg'); // will filter and only let you pick files with svg extension

第二组:返回文件
// Pick a single file directly
File file = await FilePicker.getFile(type: FileType.ANY); // will return a File object directly from the selected file

第三组:多选,返回多个文件的地址和名字
// Multi file path
Map filesPaths;
//可以多选任何文件
filePaths = await FilePicker.getMultiFilePath(); // will let you pick multiple files of any format at once
//可以多选指定后缀的文件
filePaths = await FilePicker.getMultiFilePath(fileExtension: 'pdf'); // will let you pick multiple pdf files at once
//可以多选图片
filePaths = await FilePicker.getMultiFilePath(type: FileType.IMAGE); // will let you pick multiple image files at once

List allNames = filePaths.keys; // List of all file names
List allPaths = filePaths.values; // List of all paths
String someFilePath = filePaths['fileName']; // Access a file path directly by its name (matching a key)

你可能感兴趣的:(Flutter)