What I've been trying to attempt is to update the values of an array that is concatenated within a map. Here is the data structure:
As you can observe, I want to add a new map within the "tasks" field. A map containing the same data as the current map the "tasks" field has. This is my approach:
int index = list
.indexWhere((element) => element.containsKey('tasks'));
// Update the 'tasks' field of the element at the found index
transaction
.update(catalogueCollection.doc(widget.llistId), {
'list.$index.tasks': FieldValue.arrayUnion([
{
'correct': true,
'value': '',
},
]),
});
}
});
},
What this does is somehow overwrite my entire list array (I think?) and make my list into a map even tho it was a list beforehand. It overall makes me confused and would like a way to only update the tasks field so that I can add new maps in them. Appreciate it. This is my first question in Stackoverflow so I hope I'm being clear with my problem :)