I am trying to add key value pairs to a map of maps in a firestore document. You can see the document set up below. The "Bills" map consists of key value pairs representing each bill. Each bill is represented by a map. For example: "Bill 1" consists of key value pairs which represent the name of the item and the cost of the item.
I want to add key value pairs to the bill. For example, I want to add an item to "Bill 1", so that it consists of both "Bacon: 14" and the other items I add.
Here is the code I have right now. However, this code simply replaces Bacon with the new item I add. It doesn't add the new value to the existing map, simply replaces the entire map (the contents of Bill 1) with the new item and cost.
Here is the current code:
static Future addItemToBill(GroceryItem groceryItem, double cost) async {
try{
final FirebaseUser currentUser = await FirebaseAuth.instance.currentUser();
int currentBillNumber = await getBillCount(currentUser.uid);
if(currentBillNumber == 0){
currentBillNumber = 1;
}
final DocumentReference documentReference = usersCollection.document(currentUser.uid);
await documentReference.updateData({
"Bills.Bill $currentBillNumber": {
"${groceryItem.itemName}" : cost
}
});
}catch(error){
}
}
Thank you for the help!
