I want to call an async api request inside setState but when I make setState async, It does not work properly. Otherwise, I can not await for the response. My request in controller:
void fetchList() async {
isLoading(true);
try {
var _list = await Requests.getYesillemeList();
if (_list != null) {
yList.value = _list;
}
} finally {
reOrderList();
isLoading(false);
}
}
If I call controller.fetchList() inside setState, I can not get response even it is awaiting for the response inside fetchList function. I am getting response when I make setState async, make fetchList Future of void and await for controller.fetchList inside setState but then rest of the code is not working properly. So, how can I call my api request inside setState and wait for a response.