Mt Khalifa
Mt Khalifa

Reputation: 498

firebase storage ERORR

I don't know what is the problem but the problem is with StorageTaskSnapsot and onComplete
the error says The getter 'onComplete' isn't defined for the type 'StorageUploadTask'

FirebaseStorage storage = FirebaseStorage.instance;

  uploadPic() async {
    //String fileName = path.basename(_image1.path);
    StorageReference reference =
        storage.ref().child("image1" + DateTime.now().toString());
    StorageUploadTask uploadTask = reference.putFile(_image1);
    StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
    String url = await taskSnapshot.ref.getDownloadURL();
    imageUrl1 = url;
    return url;
  }

Upvotes: 0

Views: 64

Answers (1)

Huthaifa Muayyad
Huthaifa Muayyad

Reputation: 12383

This will work:

  FirebaseStorage storage = FirebaseStorage.instance;

  uploadPic() async {
    //String fileName = path.basename(_image1.path);
    Reference reference = storage.ref().child("image1" + DateTime.now().toString());
    String url = await reference.putFile(_image1).then((_) => reference.getDownloadURL());
    return url;
  }

And this also:

   FirebaseStorage storage = FirebaseStorage.instance;
  uploadPic() async {
    //String fileName = path.basename(_image1.path);
    Reference reference = storage.ref().child("image1" + DateTime.now().toString());
    try {
      await reference.putFile(_image1);
    } on FirebaseException catch (e) {
      print(e);
    }
    return reference.getDownloadURL();
  }

Upvotes: 1

Related Questions