initAsync method

  1. @override
  2. @mustCallSuper
Future<bool> initAsync()
override

Initialize any 'time-consuming' operations at the beginning. Initialize asynchronous items essential to the Mobile Applications. Typically called within a FutureBuilder() widget.

Implementation

@override
@mustCallSuper
Future<bool> initAsync() async {
  /// It's been done. Don't run again.
  if (futureBuilt) {
    return futureBuilt;
  }
  futureBuilt = true;

  /// This will call any and all Controllers that need asynchronous operations
  /// completed before continuing.
  /// No 'setState()' functions are allowed to fully function at this point.
  _rebuildAllowed = false;
  for (final listener in _beforeList) {
    await listener.initAsync();
  }

  for (final con in _controllerList) {
    futureBuilt = await con.initAsync();
    // Don't continue if there's an error.
    if (!futureBuilt) {
      break;
    }
  }
  // ignore: invariant_booleans
  if (futureBuilt) {
    for (final listener in _afterList) {
      await listener.initAsync();
    }
  }
  _rebuildAllowed = true;
  // Set the flag
  return futureBuilt;
}