awaitData method
dynamic
awaitData({})
Use the awaitData method when initial fetching data for a widget. E.g. When your page first loads and you want to populate your widgets with data.
init() async { awaitData('home', perform: () async { ... await fetchApiData(); }); }
... in your widget Text( isLoading('home') ? 'YES Loading' : 'Loading Finished').
Implementation
awaitData(
{String name = 'default',
required Function perform,
bool shouldSetStateBefore = true,
bool shouldSetStateAfter = true}) async {
_updateLoadingState(
shouldSetState: shouldSetStateBefore, name: name, value: true);
overrideLoading = true;
try {
await perform();
} on Exception catch (e) {
NyLogger.error(e.toString());
}
hasInitComplete = true;
_updateLoadingState(
shouldSetState: shouldSetStateAfter, name: name, value: false);
}