flutter_file_picker
flutter_file_picker copied to clipboard
[Suggestion] Interop between PlatformFile and XFile
The plugin uses PlatformFile
to provide a cross-platform File implementation.
This is fine by itself. However official Flutter plugins use cross_file.
For example: a pubspec contains both file_picker
and camera
.
Now there are 2 different cross platform file implementations that someone could use.
Why don't we migrate to using XFile instead? This also eliminates the need for having to convert between the two.
I.e. the result of CameraController.stopRecording()
doesn't have to be converted to a PlatformFile
after recording, which in itself involves another Future for the size & bytes.
This issue is stale because it has been open for 14 days with no activity.
cc @miguelpruivo
What would be the implications in the file picker for this?
What would be the implications in the file picker for this?
A) return an XFile from the file picker methods, instead of PlatformFile's. Since PlatformFile
and XFile
are both wrappers around dart:io's File class, this seems doable?
The only thing I don't exactly know is how we would keep track of the new identifier attribute? Perhaps let PlatformFile extend XFile? Or provide a method like PlatformFile.fromXFile(file)
?
B) updating the documentation on how you could create an XFile from a PlatformFile and the other way around (from XFile to PlatformFile). (perhaps give the camera
plugin as a usage example)
The PlatformFile contains multiple handy features as well as being able to abstract Web implementation which doesn’t support IO imports.
Anyway, I think I can add a way to retrieve a XFile directly from the PlatformFile and that can be a plus for some.
This issue is stale because it has been open for 14 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
It would be great if we could retrieve a XFile from file_picker because it makes it easier to use this package in combination with other packages.
This could make sense indeed. I'll consider it.
Flutter WEB: I am using both packages in one widget. Any news?
Any update or workaround - I am using XFile extensively and would like to use this package. Any way to convert PlatformFile to XFile?
I use following code convert PlatformFile to XFile with withData:true
var result = await FilePicker.platform.pickFiles();
if (kIsWeb) {
return result?.files.map((f) => XFile.fromData(f.bytes!, name: f.name, length: f.size)).toList()??[];;
} else {
return result?.files.map((f) => XFile(f.path!, name: f.name, bytes: f.bytes, length: f.size)).toList()??[];;
}
I think file_picker should optionally not copy the file to a temporary path if the app has MANAGE_EXTERNAL_STORAGE
permission.
Of course, this is an edge case but this should be handled by the plugin.
Added in the last version (7.1.0) you can now retrieve the files as xFiles
or individually with xFile
getter.
Thanks!