List responseJson;
List eventDetails = [];
Future<String> fetchPost() async {
final response = await http.get(
"https..",
headers: {
HttpHeaders.AUTHORIZATION:
"Bearer ..."
});
for(var i = 0; i< (responseJson?.length ?? 0);i++) {
final eventDetailsResponse = await http.get(
"https:.." + responseJson[i]["id"].toString(),
headers: {
HttpHeaders.AUTHORIZATION:
"Bearer .."
});
eventDetails.add(json.decode(eventDetailsResponse.body));
}
this.setState(() {
responseJson = json.decode(response.body);
print(eventDetails);
print(responseJson);
});
你好!我有一个数组定义,我用数组填充数组,每个元素都是API调用的结果,然后我使用函数this.setState来触发列表视图更新,在第一次运行时eventDetails为空,但是在第二次运行时,它会填充数据,我该如何让它等待?
提前谢谢。