onStateError method
Call the latest SateX object's error routine Possibly the error occurred there.
Implementation
bool onStateError(FlutterErrorDetails details) {
//
final state = lastState;
// If it's this object, it will call its own later
bool caught = state != null && state != this;
if (caught) {
//
try {
//
final stack = details.stack?.toString();
caught = stack != null;
if (caught) {
// That State object's build() function was called.
var name = state.toString();
name = name.substring(0, name.indexOf('#'));
caught = stack.contains('$name.build');
if (!caught) {
// If it involves particular libraries
final library = details.library;
caught = library != null &&
(library.contains('gesture') || library.contains('widgets'));
}
// Call the StateX's onError() function
if (caught) {
_errorStateName = name;
state.onError(details);
} else {
_errorStateName = null;
}
// // Always test if there was an error in the error handler
// // Include it in the error reporting as well.
// if (hasError) {
// _onErrorInHandler();
// }
}
} catch (e, stack) {
// This is a public function. ALWAYS catch any error or exception
// Throw in DebugMode.
if (kDebugMode) {
// Set the original error routine. Allows the handler to throw errors.
FlutterError.onError = _prevErrorFunc;
// Rethrow to be handled by the original routine.
rethrow;
} else {
// Record the error
recordException(e, stack);
// Record error in device's log
_logPackageError(
e,
library: 'part08_app_statex.dart',
description: 'Error in onStateError()',
);
}
}
}
return caught;
}