I have a list of Map that contains bank data and now for creating chart it requires key and value..
void main() {
List<Map<String, dynamic>> maplist = [
{
'Bank': 'HDFC',
'Balance': 10900.00,
'Transactions': []
},
{
'Bank': 'AXIS',
'Balance': 5900.00,
'Transactions': []
},
{
'Bank': 'UCO',
'Balance': 4200.00,
'Transactions': []
},
{
'Bank': 'ICICI',
'Balance': 2300.00,
'Transactions': []
},
{
'Bank': 'KOTAK',
'Balance': 1200.00,
'Transactions': []
},
];
Map<String, double> chartData = {};
// i want following result in chartData
{
'HDFC':10900, 'AXIS':5900,'UCO':4200,'OTHERS':3500}
}
}
it should take first 3 banks and fourth key ‘OTHERS’ should be present sum of all other bank’s balance
2
Answers
just use this function for that:
Full example is:
This should work for you required case.
We are getting first 3 elements and for others we are doing summation of all balances.