catchAsyncError method
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 {
//
final details = FlutterErrorDetails(
exception: error,
stack: error is Error ? error.stackTrace : null,
library: 'app_statex.dart',
context: ErrorDescription('While in initAsync()'),
);
//
try {
// App State's onError routine
_currentFlutterOnError?.call(details);
//
_caughtAsyncError = await onCatchAsyncError(error);
} catch (e, stack) {
_caughtAsyncError = false;
final details = FlutterErrorDetails(
exception: e,
stack: stack,
library: 'app_state.dart',
context: ErrorDescription('Exception in onCatchAsyncError()'),
);
logErrorDetails(details);
}
try {
// Ignored if already caught
if (!_caughtAsyncError) {
_caughtAsyncError = await inCatchAsyncError?.call(error) ?? false;
}
} catch (e, stack) {
final details = FlutterErrorDetails(
exception: e,
stack: stack,
library: 'app_state.dart',
context: ErrorDescription('Exception in inCatchAsyncError()'),
);
logErrorDetails(details);
}
try {
// May have its own error handler for Asynchronous operations.
// So to possibly 'clean up' before falling out.
onAsyncError(details);
// The 'inline' version of the initAsync() error handler takes last precedence.
inAsyncError?.call(details);
} catch (e, stack) {
// Throw in DebugMode.
if (v.kDebugMode) {
// Rethrow to be handled by the original routine.
rethrow;
} else {
final details = FlutterErrorDetails(
exception: e,
stack: stack,
library: 'app_state.dart',
context: ErrorDescription('Exception in inCatchAsyncError()'),
);
logErrorDetails(details);
}
}
return _caughtAsyncError;
}