initAsync method

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

Asynchronous operations must complete successfully.

Implementation

@override
@mustCallSuper
Future<bool> initAsync() async {
  // Always return true. It's got to continue for now.
  const init = true;

  // No 'setState()' functions are allowed to fully function at this point.
  _setStateAllowed = false;

  int cnt = 0;
  StateXController con;

  // While loop the active list itself so to allow for additional controllers to be added in a previous initAsync()
  while (cnt < controllerList.length) {
    con = controllerList[cnt];
    try {
      final init = await con.initAsync();
      if (!init) {
        // Note the failure but ignore it
        final e = Exception('${con.runtimeType}.initAsync() returned false!');
        _initAsyncError(e, con);
      }
    } catch (e) {
      // Pass the error to the controller to handle
      _initAsyncError(e, con);
      // Have it handled by an error handler.
      rethrow;
    }
    cnt++;
  }
  _setStateAllowed = true;

  /// No 'setState()' functions are necessary
  _setStateRequested = false;

  return init;
}