safe_bloc library

Classes

BaseEffect
General parent effect.
Emitter<State>
An Emitter is a class which is capable of emitting new states.
SafeBloc<EVENT, STATE>
An extended class to SafeBlocWithPresentation that uses BaseEffect class as EFFECT. Additionally, it also emits an UnexpectedErrorEffect if exception occurs during some use action.
SafeBlocBase<STATE, EFFECT>
SafeBlocWithPresentation<EVENT, STATE, EFFECT>
A class that extends Bloc and encapsulates the Emitter with a SafeEmitter that catches all exceptions using a try-catch block and processes them based on specified parameters.
SafeCubit<STATE>
An extended class to SafeCubitWithPresentation that uses BaseEffect class as EFFECT. Additionally, it also emits an UnexpectedErrorEffect if exception occurs during some use action.
SafeCubitWithPresentation<STATE, EFFECT>
A class that extends Cubit for a safeCall method that catches all exceptions using a try-catch block and processes them based on specified parameters.
SafeEmitter<State>
An SafeEmitter is a class which is capable of emitting new states. Also checks if stateController is not closed before each emit.
TrackingIdService
UnexpectedError
Object that stores information about exceptions thrown in Blocs and Cubits.
UnexpectedErrorBase
API that is implemented by Bloc/Cubit's error states and effects.
UnexpectedErrorEffect
Error effect that is emitted by SafeBloc/SafeCubit if exception in its event handler/method occurs.
UnexpectedErrorHandler<BLOC extends SafeBlocBase<STATE, BaseEffect>, STATE>
Widget that listens to the events and states that implement UnexpectedErrorBase in specified the BLOC. Subsequently, it calls onErrorAction in case of error event or displays a errorScreen in case of error state.

Mixins

SafeBlocBaseMixin<STATE, EFFECT>

Extensions

CubitExtensions on Cubit<State>
Calls emit only and only if underlying bloc is not closed.

Functions

blocPresentationTest<B extends BlocPresentationMixin<State, Event>, State, Event>(String description, {required B build(), FutureOr<void> setUp()?, State seed()?, FutureOr<void> act(B bloc)?, Duration? wait, int skip = 0, List<State> expect()?, FutureOr<void> verify(B bloc)?, Matcher errors()?, FutureOr<void> tearDown()?, Object? tags, List<Event> expectEvents()?}) → void
testBloc<B extends BlocPresentationMixin<State, Event>, State, Event>({required B build(), FutureOr<void> setUp()?, State seed()?, FutureOr<void> act(B bloc)?, Duration? wait, int skip = 0, List<State> expect()?, FutureOr<void> verify(B bloc)?, Matcher errors()?, FutureOr<void> tearDown()?, List<Event> expectEvents()?}) Future<void>
Internal blocPresentationTest runner which is only visible for testing. This should never be used directly -- please use blocPresentationTest instead.

Typedefs

Callback = Future<void> Function(String trackingId)
Emit<STATE> = void Function(STATE state)
ErrorEffectGetter<EFFECT> = EFFECT Function(UnexpectedError error)
ErrorMapper<STATE> = STATE? Function(Object error)
ErrorStateGetter<STATE> = STATE Function(UnexpectedError error)
InvokeEffect<EFFECT> = void Function(EFFECT effect)
OnError = Future<void> Function(Object? error, StackTrace stackTrace, String? trackingId)
OnErrorSync = void Function(Object? error, StackTrace stackTrace, String? trackingId)
OnIgnoreError = Future<void> Function(Object? error, StackTrace stackTrace)
SafeEventHandler<Event, State> = FutureOr<void> Function(Event event, SafeEmitter<State> emit, {required String trackingId})
An event handler is responsible for reacting to an incoming Event and can emit zero or more states via the SafeEmitter. Contains a unique trackingId that can be passed to emitter for tracking the event.
SyncCallback = void Function(String trackingId)
UnexpectedErrorActionCallback = Future<void> Function(BuildContext context, UnexpectedError error)
UnexpectedErrorWidgetBuilder = Widget Function(BuildContext context, UnexpectedError error)