flutter_file_selector 文件选择插件,支持多选 ,演示示例在example目录
我代码我传到码云上了,点我跳转
下面是效果图: 第三张是ios端



本插件使用到的依赖
| 插件依赖 | pub仓库地址 |
|---|---|
| ermission_handler 权限申请 | pub |
| file_picker 调用选择器(IOS端使用的是这个) | pub |
- 使用 flutter_file_selector:
1 2 3 4 | # 在pubspec.yaml 中引入依赖 flutterfileselector: git: url: https://gitee.com/jrnet/flutter_file_selector |
2.直接使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | FlutterSelect( /// 标题 title: "选择文档", /// 按钮 btn: Text("选择文档"), /// 最大可选 maxCount: 1, /// 开启筛选 isScreen: true, /// 选择器展示的文件格式 /// 往数组里添加需要展示出来选择的格式 fileTypeEnd: [".pdf", ".doc", ".docx","xls","xlsx"], valueChanged: (v){ v.forEach((element) { //返回的参数: // File file; // String fileName; // int fileSize; // String filePath; // int fileDate; log('选择了'+element.filePath) ; }); }, ), |
注意:
安卓需配置目录访问权限 配置AndroidManifest.xml 文件,application里加入如下 file_select_flutter.xml不用创建 插件中已集成:
1 2 3 4 5 6 7 8 9 10 11 | <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileProvider" android:exported="false" android:grantUriPermissions="true" tools:replace="android:authorities"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_select_flutter" tools:replace="android:resource" /> </provider> |
FlutterSelect可选参数
| 参数名 | 说名 |
|---|---|
| String title | 标题 |
| List fileTypeEnd | 展示的文件类型 默认:".pdf , .docx , .doc" |
| String pdfImg | pdf图标 |
| String wordImg | word图标 |
| String exelImg | exelImg图标 |
| bool isScreen | 默认关闭筛选 |
| int maxCount | 可选最大总数 默认 9 |
FileModelUtil的参数:
| 参数名 | 说名 |
|---|---|
| File file | 文件 |
| String fileName | 文件名称 |
| int fileSize | 文件大小 |
| String filePath | 文件路径 |
| int fileDate | 文件日期时间 |