JuiceBloc<TState extends BlocState> class
A bloc that manages state through use cases.
JuiceBloc provides structured state management by routing events to dedicated use cases, which encapsulate business logic and emit state changes. It uses composition of focused components rather than deep inheritance.
Example:
class CounterBloc extends JuiceBloc<CounterState> {
CounterBloc() : super(
CounterState(count: 0),
[
() => UseCaseBuilder(
typeOfEvent: IncrementEvent,
useCaseGenerator: () => IncrementUseCase(),
),
],
);
}
- Implemented types
-
- StateStreamableSource<
StreamStatus< TState> > - Emittable<
StreamStatus< TState> > - ErrorSink
- StateStreamableSource<
- Implementers
- Available extensions
Constructors
-
JuiceBloc(TState initialState, List<
UseCaseBuilderGenerator> useCases, [List<AviatorBuilder> aviatorBuilders = const [], JuiceLogger? customLogger, BlocErrorHandler errorHandler = const BlocErrorHandler()]) - Creates a JuiceBloc with initial state and use cases.
Properties
-
currentStatus
→ StreamStatus<
TState> -
The current status with metadata.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- isClosed → bool
-
Whether the bloc is closed.
no setteroverride
- isClosing → bool
-
True once close has started — and stays true after it completes
(then isClosed is true as well). Monotonic, like
SyncBloc's own flag it now formalizes.no setter - logger → JuiceLogger
-
no setter
- oldState → TState
-
The previous state of the bloc.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → TState
-
The current state of the bloc.
no setter
-
stream
→ Stream<
StreamStatus< TState> > -
Stream of status changes.
no setteroverride
Methods
-
addError(
Object error, [StackTrace? stackTrace]) → void -
Reports an error which triggers onError.
override
-
close(
) → Future< void> -
Closes the bloc and releases all resources.
override
-
dispose(
) → void - Synchronous cleanup method for Flutter widget compatibility.
-
emit(
StreamStatus< TState> status) → void -
Emits a new status directly.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onError(
Object error, StackTrace stackTrace) → void - Called when an error occurs. Override to customize error handling.
-
select<
T> (T selector(TState state), {Set< String> ? groups}) → Stream<T> -
Available on JuiceBloc<
Returns a stream that only emits when the selected value changes.TState> , provided by the StateSelection extension -
selectWith<
T> (T selector(TState state), {required bool equals(T previous, T current), Set< String> ? groups}) → Stream<T> -
Available on JuiceBloc<
Returns a stream that only emits when the selected value changes, using a custom equality function.TState> , provided by the StateSelection extension -
send(
EventBase event) → Future< void> - Sends an event to be processed by its registered use case.
-
sendAndWait(
EventBase event, {Duration timeout = const Duration(seconds: 30)}) → Future< StreamStatus< TState> > - Sends an event and waits for processing to complete.
-
sendAndWaitResult<
TResult> (ResultEvent< TResult> event, {Duration timeout = const Duration(seconds: 30)}) → Future<OperationResult< TResult, TState> > -
Available on JuiceBloc<
SendsTState> , provided by the ResultEventOps extensioneventand returns its terminal status plus typed value. -
sendCancellable<
T extends CancellableEvent> (T event) → T - Sends a cancellable event and returns it for cancellation control.
-
sendForResult<
TResult> (ResultEvent< TResult> event, {Duration timeout = const Duration(seconds: 30)}) → Future<TResult> -
Available on JuiceBloc<
SendsTState> , provided by the ResultEventOps extensioneventand returns its value, or throws the failure's error (with its stack trace). A cancel throws StateError. -
start(
) → void - Triggers an update with the current state.
-
tester(
) → BlocTester< JuiceBloc< TState> , TState> -
Available on JuiceBloc<
Creates a BlocTester for this bloc.TState> , provided by the BlocTesterExtension extension -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited