I'm getting my documents from firebase keeping in a List. Currently I have this content in the list:
[{date: 02/02/2019, name: John}, {date: 03/03/2020, name: Louise}]
Then, in the following method, I transform this list to put in a map with my desired formatation.
Map formatMap(list){
if(list.length > 1){
for(int i = 0; i < list.length; i ++){
dateFormatted = _formatDate(list[i]['date']);
print(dateFormatted);
if(i == 0){
myMap[dateFormatted] = [];
}
myMap[dateFormatted].add({'date': list[i]['date'], 'name': events[i]['name']});
}
}else{
dateFormatted = _formatDate(list['date']);
myMap[dateFormatted] = [{'date': list['date'], 'name': list['name']}];
}
return myMap;
}
I'm doing it because my expected result is:
{2020-12-31 12:00:00.000Z: [{date: 02/02/2019, name: John}, {date: 03/03/2020, name: Louise}]}
But running that method the return is:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '[]=' was called on null. E/flutter (17862): Receiver: null E/flutter (17862): Tried calling: []=(Instance of 'DateTime', Instance(length:0) of '_GrowableList')
What I'm doing wrong? How can I perform to achieve my expected result?