Undefined class StorageReference when using Firebase Storage

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<TaskSnapshot>. 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.


As mentioned by @PeterHadad there are a few breaking changes in firebase storage 5.0.1. The classes have been renamed but maintain most of their old functionalities.

You can also use .whenComplete() to get the download URL as follows-

uploadPic(File _image1) async {
   FirebaseStorage storage = FirebaseStorage.instance;
   String url;
   Reference ref = storage.ref().child("image1" + DateTime.now().toString());
   UploadTask uploadTask = ref.putFile(_image1);
   uploadTask.whenComplete(() {
      url = ref.getDownloadURL();
   }).catchError((onError) {
    print(onError);
    });
   return url;
}

Pick image from gallery and store it firebase storage in images folder like this :

final XFile? image = await ImagePicker().pickImage(source: source);
FirebaseStorage storage = FirebaseStorage.instance;
Reference ref = storage.ref().child("images/"+DateTime.now().toString());
UploadTask uploadTask = ref.putFile(File(image!.path));
uploadTask.then((res) {
  res.ref.getDownloadURL();
});

Make sure to add image_picker and firebase_storage in your pubspec.yaml file as dependencies.