handleInitializeFailedEvent method

  1. @protected
Stream<S> handleInitializeFailedEvent(
  1. FastCalculatorBlocEventPayload<R>? payload
)

Handles an event where the calculator fails to initialize by resetting the isInitialized and isInitializing flags and emitting a new state.

If the payload.error property is not null, the method logs a message indicating that the calculator failed to initialize and includes the error object in the log message. If the payload.stacktrace property is not null, the method also logs the stack trace associated with the error.

Implementation

@protected
Stream<S> handleInitializeFailedEvent(
  FastCalculatorBlocEventPayload<R>? payload,
) async* {
  // TODO: allow to log errors and stacktraces to an external tool.
  if (payload?.error != null) {
    debugLog(
      'Failed to initialize calculator',
      value: payload!.error,
      debugLabel: debugLabel,
    );

    if (payload.stacktrace != null) {
      debugLog(
        'Stacktrace',
        value: payload.stacktrace,
        debugLabel: debugLabel,
      );
    }
  }

  if (isInitializing) {
    isInitializing = false;
    isInitialized = false;

    // TODO: Notifies the state when the initialization process fails.
    yield currentState.copyWith(
      isInitializing: isInitializing,
      isInitialized: isInitialized,
    ) as S;
  }
}