Flutter & Firebase : How to check if my picture is uploaded to Firebase Storage Successfully?

Flutter & Firebase : How to check if my picture is uploaded to Firebase Storage Successfully?

I am trying to find a way to see if the picture was upload successful so that I can start and stop my LoadingScreen().

final StorageReference firebaseStorageRef = FirebaseStorage.instance
        .ref()
        .child('$path/${userID}_${timeStamp}_${number}_${tag}.jpg');

final StorageUploadTask uploadTask = firebaseStorageRef.putFile(image);

I am looking forward to hearing from all of you. Thank you in advance!


Here is how you can upload and verify if images are uploaded to FirebaseStorage:

  final StorageReference firebaseStorageRef = FirebaseStorage.instance
      .ref()
      .child('$path/${userID}_${timeStamp}_${number}_${tag}.jpg'); 
  StorageUploadTask uploadTask =
      firebaseStorageRef.putFile(image);
  StorageTaskSnapshot storageSnapshot = await uploadTask.onComplete;
  var downloadUrl = await storageSnapshot.ref.getDownloadURL();
  if (uploadTask.isComplete) {
    final String url = downloadUrl.toString();
    print(url);
    //Success! Upload is complete
  } else {
    //Error uploading file
  }

You will get the downloadUrl after the upload is complete.


You can use the onComplete property of the StorageUploadTask.

  final StorageReference firebaseStorageRef = FirebaseStorage.instance
      .ref()
      .child('$path/${userID}_${timeStamp}_${number}_${tag}.jpg'); 
  StorageUploadTask uploadTask =
      firebaseStorageRef.putFile(image);
  StorageTaskSnapshot storageSnapshot = await uploadTask.onComplete;
  // Here you know that the picture/file is succesfully uploaded.
  // You can stop your LoadingScreen().

Note that you may use some try-catch clauses to handle the errors of the async method.