Flutter Web is currently in beta, so there's a lack of available info/resources on how to do this.
I could not find any flutter packages compatible with web to do this. Any tips?
Here's my code:
uploadImage() async {
File file;
FileReader fileReader = FileReader();
InputElement uploadInput = FileUploadInputElement();
uploadInput.click();
uploadInput.onChange.listen((event) {
file = uploadInput.files.first;
fileReader.readAsDataUrl(file);
fileReader.onLoadEnd.listen((event) {
if (file.type == "image/jpg" || file.type == "image/jpeg" || file.type == "image/png") {
String base64FileString = fileReader.result.toString().split(',')[1];
//COMPRESS FILE HERE
setState(() {
userImgFile = file;
userImageByteMemory = base64Decode(base64FileString);
});
} else {
CustomAlerts().showErrorAlert(context, "Image Upload Error", "Please Upload a Valid Image");
}
});
});
}