Future _fetchData() async {
setState(() {
_showLoading = true;
});
final responses = await Future.wait([
httpHelper.fetchWorkData(widget.userId, widget.selectedDate, "day"),
httpHelper.fetchCutivationStepData(widget.selectedDate),
httpHelper.fetchFieldListData(widget.userId),
httpHelper.fetchWorkListData(),
httpHelper.fetchPestListData(),
httpHelper.fetchDisorDerListData(),
]);
setState(() {
todayDataList = responses[0];
cultivationStepData = responses[1];
fieldListData = responses[2];
workListData = responses[3];
pestListData = responses[4];
disorderListData = responses[5];
});
setState(() {
_showLoading = false;
});
print(fieldListData);
}
여러개의 요청을 리스트에 받은 후 객체에 요청 결과를 각 각 할당하면 끝.
References
https://www.youtube.com/watch?v=rhw3y9iAak8
Flutter - Best way to request Multiple APIs simultaneously
I have two URLs, and I am using the fetchData() function to parse the json. Future<Iterable> fetchData() async { var response = await http.get(firstUrl); var listOne = List<Article>();...
stackoverflow.com
728x90
'Flutter' 카테고리의 다른 글
| [Flutter] How can i get int data from TextEditingController in flutter (0) | 2022.04.27 |
|---|---|
| [Flutter] How to convert List to String without [] (0) | 2022.04.27 |
| [Flutter] sizedbox shrink with max height ; child의 크기에 따라서 박스 높이 조절하기 (0) | 2022.04.25 |
| [Flutter] loop list of widget (0) | 2022.04.23 |
| [Flutter] table 셀 너비 자동 맞춤 (0) | 2022.04.23 |