initAsync method

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

Asynchronous operations must complete successfully.

Implementation

@override
@mustCallSuper
Future<bool> initAsync() async {
  // Optionally call super for debugPrint()
  super.initAsync();

  // 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 {
      bool init = true;
      if (_runAsync || !con.initAsyncCalled) {
        init = await con.initAsync();
      }
      if (init) {
        init = await con.initAsyncState(this);
      }
      if (!init) {
        // Note the failure but ignore it
        final e = Exception('${con.runtimeType}.initAsync() returned false!');
        _initAsyncError(e, con);
      }
    } catch (e, stack) {
      // Pass the error to the controller to handle
      _initAsyncError(e, con, stack: stack);
      // Have it handled by an error handler.
      rethrow;
    }
    cnt++;
  }
  _setStateAllowed = true;

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