I have an object with following data for instance (Elasticsearch result)
{createdat: {raw: 2022-01-26T16:49:24.000Z}, images: {raw: []}}
In Flutter I would like to (re)map this object to look like
{createdat: 2022-01-26T16:49:24.000Z, images: []}
So the challenge is to get the value of each "raw" and get it one level up.
Is there an easy method to solve that task?
CodePudding user response:
You can do something like this:
void main() {
final originalMap = {
'createdat': {'raw': '2022-01-26T16:49:24.000Z'},
'images': {'raw': []}
};
final convertedMap = originalMap.map((key, value) =>
MapEntry(key, value['raw']));
print(convertedMap);
}
