Reputation: 365
I have a Dart Map() which I want to perform a .map() operation on to turn it into a second map. However, this conversion requires an await call. How might I do this in Dart? The below gives me an error of course, but how does one achieve this in one line?
Map secondMap = firstMap.map((key, value) async => MapEntry("key", await someAsyncFunction()))
Upvotes: 1
Views: 704
Reputation: 824
Here is one way to do it:
final secondMap = Map.fromEntries(await Future.wait(firstMap.entries.map((entry) async => MapEntry(entry.key, await someAsyncFunction()))));
Upvotes: 2