0

I'm currently working on uploading multiple images to firebase and getting the downloadUrl into a list.

  _imageList.forEach((element) async {
                      final StorageReference _ref = FirebaseStorage.instance
                          .ref()
                          .child("Users/ads/"); 
                      StorageUploadTask uploadTask =
                          _ref.putFile(element as i.File);

                      await uploadTask.onComplete;
                      print("Images uploaded");
                      String image_links = await _ref.getDownloadURL();
                      _imageUrls.add(image_links);// _imageUrls is a List
                    });

and now I wanna assign the _imageUrls into firestore.

 Map<String, dynamic> ads = {
                      'adTitle': widget.title,
                      'adPrice': widget.price,
                      'adCategory': widget.dropdownValue,
                      'adCondition': this.newCondtionVal,
                      'adDesc': widget.desc,
                      'user_id': uID,
                      'imageUrls_List': _imageUrls,//Images goes hear

           
                    };
                    crudObj
                        .addData(ads)
                        .then((value) => {
                              showInSnackBar("dataAdded"),
                            })
                        .catchError((e) {
                      print(e);
                    });

But the problem is:
uploading data to firestore works first(Image upload is not finished yet), So now imageUrls_List slot in firestore is empty.

Is there any way to add onComplete to the getDownloadURL() function?
or
any other options to run the firestore upload after the images done with uploading?

Pranav
  • 411
  • 6
  • 19

0 Answers0