Search code examples
flutterdartflutter-image-picker

The argument type 'XFile' can't be assigned to the parameter type 'Uint8List'


I try to upload an image to firebase storage:

First: Pick an image as XFile using image_picker: ^0.8.6 package. Second: use UploadTask method to upload the XFile to the storage. But I got (The argument type 'XFile' can't be assigned to the parameter type 'Uint8List') error.

How can I convert the Xfile into Unit8List? or any kind of solution?

I have searched for a solution But I didn't find any that works for me.


Solution

  • Per the documentation:

    XFile? file = await picker.pickImage(...);
    Uint8List? bytes = await file?.readAsBytes();