Here is the structure;
I want to get the sum of all the amounts Bills[ BillStatement(amount:20, date'24/07/2020'), BillStatement(amount:30, date'24/07/2020'), BillStatement(amount:10, date'24/07/2020'), ]
CodePudding user response:
Use this method:
getItemTotal(List<BillStatement> bills){
double sum= 0.0;
bills.forEach((e) {
sum = e.amount;
}
return sum;
}
CodePudding user response:
final bills = [
BillStatement(amount:20, date:'24/07/2020'),
BillStatement(amount:30, date:'24/07/2020'),
BillStatement(amount:10, date:'24/07/2020'),
];
num totalAmount = 0;
bills.forEach((billStatement) => totalAmount = billStatement.amount);
print(totalAmount);