Reputation: 41
I use Flutter. I would like to update the value of CH to be false in Firebase only for the week of 26/4/2020. When is there a way?
Failed Ex.cord:
_firestore.collection('member').document(uidMember[index])
.updateData({'statistics': [{'${submit}': val,}]});
Upvotes: 4
Views: 3625
Reputation: 268384
First create a List
which has the updated items. Create a Map
using the list and then update this map to the cloud firestore:
List<Map<String, dynamic>> updatedList = [...];
Map<String, dynamic> updatedData = {
'statistics': updatedList,
};
var collection = FirebaseFirestore.instance.collection('collection');
collection
.doc('doc_id')
.update(updatedData);
Upvotes: 0
Reputation: 5829
Given the Firestore snippet you shared you can do something like the following code to update data:
var ref = _firestore.collection('member').document(uidMember[index]);
ref.get() => then(function(snapshot) {
List<dynamic> list = List.from(snapshot.data['statistics']);
//if you need to update all positions of the array do a foreach instead of the next line
list[0].CH = false;
ref.updateData({
'statistics': list
}).catchError((e) {
print(e);
});
}.catchError((e) {
print(e);
});
NOTE: I haven't tested this so you might have to adapt it, but should be a good starting point.
Upvotes: 3