toError method

  1. @override
AsyncState<S> toError(
  1. Object error, {
  2. String? message,
  3. StackTrace? stackTrace,
})
override

Returns a new AsyncState with the given error information.

error is the error object or exception. message is an optional error message. stackTrace is an optional stack trace for debugging.

Use this to transition to an error state from any other state.

data carries over, so the previous value stays available while the error is shown. when and whenData take their error branch regardless; read data directly to show it. The AsyncState.error and AsyncState.errorWithState constructors have no previous value to carry and leave data null.

Implementation

@override
AsyncState<S> toError(
  Object error, {
  String? message,
  StackTrace? stackTrace,
}) {
  return AsyncState<S>._(
    status: AsyncStatus.error,
    data: data,
    errorState: ErrorState(error, message: message, stackTrace: stackTrace),
  );
}