catchAsyncError method

  1. @override
Future<bool> catchAsyncError(
  1. Object error
)
override

Catch it if the initAsync() throws an error The FutureBuilder will fail, but you can examine the error

Implementation

@override
Future<bool> catchAsyncError(Object error) async {
  try {
    //
    InformationCollector? collector;
    assert(() {
      collector = () => <DiagnosticsNode>[
            MessageProperty('initAsync', error.toString()),
            DiagnosticsProperty<StateX<T>>(
              'FutureBuilder',
              this,
              style: DiagnosticsTreeStyle.errorProperty,
            ),
          ];
      return true;
    }());

    final details = FlutterErrorDetails(
      exception: error,
      stack: error is Error ? error.stackTrace : null,
      library: 'app_state.dart',
      context: ErrorDescription('While in FutureBuilder Async'),
      informationCollector: collector,
    );

    // State object's error handler
    // Before onCatchAsyncError()
    onError(details);

    // // App State's onError routine
    // appState?._currentFlutterOnError?.call(details);

    // Before onAsyncError()
    _caughtAsyncError = await onCatchAsyncError(error);

    // May have its own error handler for Asynchronous operations.
    // So to possibly 'clean up' before falling out.
    onAsyncError(details);
  } catch (e) {
    _caughtAsyncError = false;
    final details = FlutterErrorDetails(
      exception: e,
      stack: e is Error ? e.stackTrace : null,
      library: 'app_state.dart',
      context: ErrorDescription('Error in onCatchAsyncError()'),
    );
    logErrorDetails(details);
  }
  return _caughtAsyncError;
}