Search code examples
firebaseflutterdartfile-upload

A value of type 'Future<String>' can't be assigned to a variable of type 'String'


I have this code where am supposed to upload an image and get the downloaded url but whenever i do that I get this error

image upload error

my url is String url;. So please why is this not working as it is supposed to

PS I checked other website to learn how to properly upload but it keeps giving me an error or is there a better way to do this.

enter image description here

My code image


Solution

  • uploadTask.whenComplete(()async{
    url = await refs.getDownLoadURL();
    ....
    });
    

    Since it returns a Future you need to wait for it to be accessed