awaitData method

dynamic awaitData({
  1. String name = 'default',
  2. required Function perform,
  3. bool shouldSetStateBefore = true,
  4. bool shouldSetStateAfter = true,
})

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);

  try {
    await perform();
  } on Exception catch (e) {
    NyLogger.error(e.toString());
  }

  _updateLoadingState(
      shouldSetState: shouldSetStateAfter, name: name, value: false);
}