iam trying to open a file by using file_icker.dart & open_file.dart. iam using AS articfox, flutter 2.5 and android 11 (did tried on emulator and androdi device (Remi note)).
this is my openFile code:
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");
}
}
and This is the output:
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
What confused me is that file_picker clearly confirmed the selected file :
File loaded and cached at:/data/user/0/com.example.bismillah/cache/file_picker/pdf_tmp_fie.pdf
But when i tried to assign that path to a file which i planned to open with open_file.dart it said file not exist. can someone please help me understand whats goin on. Thanks