I have ScopedModel which integrated with FireStore in flutter. Whenever i add or update record in FireStore data getting refreshed and adding duplicated values in model each time. How to remove existing value before FireStore reloading same.
ScopedModel - for loading intial values
Firestore.instance
.collection('categoryMaster')
//.where('isActive', isEqualTo: true)
.orderBy('categoryCode')
.snapshots()
.listen((data) {
data.documents.forEach((doc) {
finalData.add(Category.map(doc));
});
}).asFuture();
Trying to update value in sub classes, After update again same values added in model. Ex.. if i have 5 record as [a,b,c,d,e] after update 5 more values added in same list [a,b,c,d,e,a,b,c,d,e]
Firestore.instance.collection('categoryMaster')
.document(category[index].field1)
.updateData({
"isActive": category[index].isActive
? false
: true
}).whenComplete(() {
setState(() {
print(category.length);
});
}).catchError((e) {
print(e);
});
how to avoid this duplicate values form model?