Reputation: 486
I have created a method that makes API call. It receives and the returns the data as example bellow shows:
Future<List<SearchResult>> postCall() async {
List<SearchResult> searchResult = [];
....
return searchResult;
}
And, I have tried to store the response into the List
as bellow code shows. But, I have got this error:
Avalue of type Future<List<SearchResult>> can't be assigned to a variable of type List<sResult>
I am trying to store the response into list as List is easier for me to loop through the data. Is there an alternative way to store the response in the List
? or how can I iterate through the nested objects using FutureBuilder
?
List<SearchResult> sResult = [];
sResult = serviceOne.postCall();
Upvotes: 0
Views: 368
Reputation: 15089
I think it should be this, because it is result of Future
.
sResult = await serviceOne.postCall();
Upvotes: 1