Undefined class StorageReference when using Firebase Storage

后端 未结 3 1190
甜味超标
甜味超标 2020-12-02 02:43

i am trying to upload image, and the same process is working for my other app, but here it gives these errors, can you guy plz help?

Future getImage1() async          


        
3条回答
  •  离开以前
    2020-12-02 03:14

    Starting from Version firebase_storage 5.0.1:

    You have to do the following:

    FirebaseStorage storage = FirebaseStorage.instance;
    Reference ref = storage.ref().child("image1" + DateTime.now().toString());
    UploadTask uploadTask = ref.putFile(_image1);
    uploadTask.then((res) {
       res.ref.getDownloadURL();
    });
    

    StorageReference class has been removed and now you have to use the class Reference. UploadTask extends Task, which also implements Future. Therefore all the methods that are in the class Future can be used on the class UploadTask.

    So to get the url of the image, you need to use the then() method which registers a callback to be called when this future completes.

提交回复
热议问题