【发布时间】:2021-09-15 17:39:20
【问题描述】:
我正在尝试使用 file_icker.dart 和 open_file.dart 打开文件。 我正在使用 AS articfox、flutter 2.5 和 android 11(在模拟器和安卓设备上尝试过(Remi note))。
这是我的 openFile 代码:
void _openFileExplorer() async {
setState(() => _loadingPath = true);
try {
_directoryPath = null;
_paths = (
await FilePicker.platform.pickFiles(
type: _pickingType,
allowMultiple: _multiPick,
onFileLoading: (FilePickerStatus status) => print(status),
allowedExtensions: (_extension?.isNotEmpty ?? false)
? _extension?.replaceAll(' ', '').split(',')
: null,
)
)?.files;
} on PlatformException catch (e) {
print("Unsupported operation" + e.toString());
} catch (ex) {
print(ex);
}
if (!mounted) return;
_loadingPath = false;
_fileName =
_paths != null
? _paths!.map((e) => e.name).toString()
: '...';
if (_paths != null) {
print("FILEPATH FOUND==> $_paths");
//try crating File using path
File file = File(_paths.toString());
//checking file exist
(await file.exists()) ? print("file exist") : print("file !exist");
//what the hell...try open it !!
final _result = await OpenFile.open(_paths.toString());
print("result: "+ _result.message);
}
else {
print("nope");
}
}
这是输出:
D/FilePickerUtils( 9666): File loaded and cached at:/data/user/0/com.example.bismillah/cache/file_picker/pdf_tmp_fie.pdf
D/FilePickerDelegate( 9666): File path:[com.mr.flutter.plugin.filepicker.FileInfo@98399df]
I/flutter ( 9666): FilePickerStatus.done
I/flutter ( 9666): FILEPATH FOUND==> [PlatformFile(path: /data/user/0/com.example.bismillah/cache/file_picker/pdf_tmp_fie.pdf, name: pdf_tmp_fie.pdf, bytes: null, readStream: null, size: 5948832)]
I/flutter ( 9666): file !exist
I/flutter ( 9666): result: the [PlatformFile(path: /data/user/0/com.example.bismillah/cache/file_picker/pdf_tmp_fie.pdf, name: pdf_tmp_fie.pdf, bytes: null, readStream: null, size: 5948832)] file does not exists
让我困惑的是 file_picker 清楚地确认了选择的文件:
File loaded and cached at:/data/user/0/com.example.bismillah/cache/file_picker/pdf_tmp_fie.pdf
但是当我尝试将该路径分配给我计划用 open_file.dart 打开的文件时,它说 文件不存在。有人可以帮我理解发生了什么。谢谢
【问题讨论】:
标签: flutter android-studio dart