Just after new page is created, I need to load webservice data (while loading is in progress, busy inducator should be displayed), then when loading done, show data.
My approach is load data inside initState override, this way:
void initState() {
setState(() => _isLoading = true);
fetchData().then((value) {
// Do something with data
widget.value = value;
setState(() => _isLoading = false);
});
}
super.initState();
}
Then, build method will display either loading indicator, or loaded data depend from _isLoading value.
For now, it works but I don't feel it's good way, especially afaik, setState call should be avoided inside initState.
Can you provide any tips how to do the same better, without complicating code too much? Or, my approach is acceptable in this case?