4

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");
    }
  });
});
}
Mukai Selekwa
  • 99
  • 1
  • 6

1 Answers1

-1

For the time being, I will be creating a cloud function to resize/compress the file when it is uploaded to firebase storage on the backend as workaround.

Here's a link on how to do that for those needing a workaround until this is resolved: https://www.youtube.com/watch?v=OKW8x8-qYs0

EDIT

The image picker library has been updated. The solution can be found here

Mukai Selekwa
  • 99
  • 1
  • 6