Reputation: 163
I create an expense collection in firebase but when I access it in other screen using provider every time I add new item It duplicate the previous item as I continue inserting items it duplicate them?
final summaryDataExpense = Provider.of<ExpensesData>(context).expenseList;
final filterByYearExpense = summaryDataExpense
.where((element) =>
DateTime.parse(element['itemDate']).year == currentYear)
.toList();
var totalExpenses = filterByYearExpense.map((e) => e['itemPrice']).toList();
totalExpenses return wrong length of the items existed
Upvotes: 0
Views: 137
Reputation: 4341
You need to replace type of expenseList from List to Set.
Set will take care of the duplicates.
Upvotes: 1