flutter - Flutter file_picker 包为所有文件详细信息提供空值
问题描述
我从 file_picker 包文档中复制了相同的代码,但它一直给我所有文件详细信息的空值,这是我复制的代码
FilePickerResult result = await FilePicker.platform.pickFiles();
if(result != null) {
PlatformFile file = result.files.first;
print(file.name);
print(file.bytes);
print(file.size);
print(file.extension);
print(file.path);
}
文件名、字节、大小、扩展名和路径都给出了一个空值。有谁知道这是什么原因?我尝试上传 pdf、png、jpg、doc 并为所有这些文件获取相同的 null 值。
解决方案
我正在使用最新版本: https ://pub.dev/packages/file_picker
void _openFileExplorer() async {
File _pickedFile;
FilePickerResult _filePickerResult;
setState(() {
_isLoading = true;
});
try {
_filePickerResult = await FilePicker.platform.pickFiles(
type: FileType.any,
allowedExtensions: (_extension?.isNotEmpty ?? false)
? _extension?.replaceAll(' ', '')?.split(',')
: null);
} on PlatformException catch (e) {
print("Unsupported operation" + e.toString());
}
if (_filePickerResult != null) {
setState(() {
_pickedFile = File(_filePickerResult.files.single.path);
});
}
if (!mounted) return;
{
Flushbar(
showProgressIndicator: true,
progressIndicatorBackgroundColor: Colors.blueGrey,
title: 'Status:',
message: 'File loaded: $_pickedFile',
duration: Duration(seconds: 3),
backgroundColor: Colors.green,
)
..show(context);
}
setState(() {
_isLoading = false;
});
}
推荐阅读
- python - 为什么我的 python 代码无法打开 pdf 文件?
- javascript - TypeError:props.onAdd 不是 React 函数
- python - 格式化最大和索引值 Pandas Python 的输出
- python - 如何添加一些日期/月份日期编辑对象以获取下一个日期?
- flutter - 如何在颤动中删除可搜索的下拉默认填充?
- c - 在不停止父进程的情况下获取 execv 的状态
- php - 如何防止大型“do while”循环导致 504 网关超时错误?
- openshift - post"https://tekton-pipelines-webhook.openshift-pipelines.svc:443/?timeout=30s": x509: 证书由未知权威签署
- node.js - React项目编译成功无法从浏览器查看
- javascript - 清理 axios useEffect 函数