I am trying to return a Future<List> in an async function, which is constructed when another Future completes.
Future<List<String>> myFunc() async {
<Future<List<String>> eventDescriptions;
googleCalendarApi.events.list('primary').then((events) => {
eventDescriptions = events.items.map((e) => e.description).toList();
}
return eventDescriptions;
I had assumed that the completion of the googleCalendarApi.events.list()
would asynchronously create the eventDescriptions such that it would be happy to do the Future assignment (in the Future).
But Flutter complains about the assignment because the result is a List not a Future<List> even though the assignment is done in the future!
2
Answers
So this is my solution to the problem, this does do the right thing now I understand the execution of an async function.
Try this way,