I have a table having columns id,debit,credit. I am fetching data from database and generating a list with the help of model. I want to calculate running balance from dart list which should be like this
Debit | Credit | Balance |
---|---|---|
0 | 200 | 200 |
100 | 0 | 100 |
100 | 0 | 0 |
void main() {
List<LedgerModel> ledgerList;
int? previousBalance = 2000;
ledgerList = <LedgerModel>[
LedgerModel(id: 1,debit: 0, credit: 100),
LedgerModel(id: 1,debit: 50, credit: 0),
LedgerModel(id: 1,debit: 250, credit: 0),
LedgerModel(id: 1,debit: 0, credit: 250),
LedgerModel(id: 1,debit: 0, credit: 1300),
LedgerModel(id: 1,debit: 1000, credit: 0),
];
ledgerList.forEach((element) {
print("${element.id} ${element.debit} ${element.credit} ${(previousBalance+element.credit)-element.ebit}");
});
}
class LedgerModel {
int? id;
int? debit;
int? credit;
LedgerModel({this.id,this.debit, this.credit});
}