I'm trying to upload images to firebase through firebase storage, and then create a document in firestore containing urls of the said uploaded images. For this,i use this function
void uploadImageAndCreatePage(List<File> imageFile) async {
var storage = FirebaseStorage.instance;
for(int j = 0; j<imageFile.length; j++) {
StorageReference ref = storage.ref().child("photo"+Random().nextInt(3413555).toString()+j.toString());
StorageUploadTask uploadTask = ref.putFile(imageFile[j]);
var url = "";
var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
url = dowurl.toString();
downUrl.add(url);
print("url is:" +downUrl.toString());
}
for(int i = 0; i<imageFile.length;i++){
if(i == 0){
map['ImgUrl'] = downUrl[0];
}
map['Img$i'] = downUrl[i+1 < downUrl.length?i+1:i];
}
var doc = await _reference.collection('Products').document("${titleController.text}").get();
doc.reference.setData(map);
doc.reference.collection('Reviews').document("DummyRev").setData({
"name":"null",
});
print("done");
}
The code works fine until it gets to the part where i set the data using documentreference.setData, which takes in a map value. I have this map defined as Map<String,String> map = new Map() , but it still says it's not a subtype of _InternalLinkedHashMap.. where am i going wrong with this? i have also tried to use a Map<dynamic,dynamic> and Map<String,dynamic, to no avail.