In my App I'm using image_picker and image_picker_web but it throws No podspec found for 'image_picker_web' in '.symlinks/plugins/image_picker_web/ios'
exception when running on iOS.
So I decided not to use it and pick the file like in the accepted solution here How to Pick files and Images for upload with flutter web.
Print for picked file is correct but my method returns null a I guess it returns the variable before it gets assigned a value.
I don't know html so I'm kinda lost here..
What am I doing wrong with returning the picked value?
FileReader reader = FileReader();
InputElement uploadInput = FileUploadInputElement();
Future<Uint8List> pickImage() async {
print('FirebaseImageStorageRepositoryWeb. pickImage() started');
// image_picker_web works on web but creates pod problems on iOS
// Uint8List imageData;
// String fileName;
// await picker.getImage(source: ImageSource.gallery).then((picked) {
// picked.readAsBytes().then((data) {
// imageData = data;
// });
// });
// image_picker // notworking on web...
//html
Uint8List imageData;
InputElement uploadInput = FileUploadInputElement();
uploadInput.click();
uploadInput.onChange.listen((e) {
// read file content as dataURL
final files = uploadInput.files;
if (files.length == 1) {
final file = files[0];
print(
'selected file: type:${file.type},name: ${file.name}, size: ${file.size}');
reader.onLoadEnd.listen((e) {
imageData = reader.result;
// return imageData; // not working
});
reader.onError.listen((fileEvent) {
print('Some Error occured while reading the file');
});
reader.readAsArrayBuffer(file);
}
});
return imageData;
}