setError method
Transitions the notifier to the error state with the given error information.
error
is the error object or exception that occurred.
message
is an optional error message for display.
stackTrace
is an optional stack trace for debugging.
Use this when an async operation fails.
Example:
void onError(Exception error) {
setError(error, message: 'Failed to fetch data');
}
Implementation
@protected
void setError(
Object error, {
String? message,
StackTrace? stackTrace,
}) {
return setState(
state.toError(
error,
message: message,
stackTrace: stackTrace,
),
forced: true,
);
}