Is there a way to convert dart:io File object to dart:html File? I tried html.File file = dartFile as html.File
and it isn't working
Asked
Active
Viewed 1,734 times
0

user969068
- 2,818
- 5
- 33
- 64

Henzelix
- 65
- 1
- 10
2 Answers
1
No way. But you can handle it by having different code. See bellow:
final _photos = <File>[];
final _photosWeb = <html.File>[];
if (kIsWeb == false) { //if its not web, handle dart.io file
final pickedFile = await _picker.getImage(
source: ImageSource.gallery,
imageQuality:
100,
);
File image = File(pickedFile!.path);
if (image != null) {
_photos.insert(_numberOfImage, image);
}
} else { //if its web, handle html.file
final temp = (await ImagePicker()
.getImage(source: ImageSource.camera, imageQuality: 80));
final pickedFile = await temp!.readAsBytes();
var image = html.File(temp.path.codeUnits, temp.path);
if (image != null) {
_photosWeb.insert(_numberOfImage, image);
}
}

Thiago Silva
- 670
- 6
- 18
0
No. The two file objects are completely unrelated.
I am not aware of any platform which has both the dart:io
and the dart:html
library available, so even being able to import both in the same program is surprising.

lrn
- 64,680
- 7
- 105
- 121