StatefulUseCaseBuilder class
A use case builder that maintains a single instance of a use case throughout its lifecycle.
Unlike the standard UseCaseBuilder which creates a new use case instance for each event, StatefulUseCaseBuilder reuses the same instance until explicitly closed. This is particularly useful for use cases that need to maintain state or manage resources like connections, subscriptions, or caches.
Example:
// Chat connection that maintains a single websocket instance
StatefulUseCaseBuilder(
typeOfEvent: ChatEvent,
useCaseGenerator: () => ChatConnectionUseCase(webSocketService),
)
- Inheritance
-
- Object
- UseCaseBuilderBase
- StatefulUseCaseBuilder
Constructors
- StatefulUseCaseBuilder({required Type typeOfEvent, required UseCaseGenerator useCaseGenerator, UseCaseEventBuilder? initialEventBuilder})
- Creates a StatefulUseCaseBuilder.
Properties
- eventType → Type
-
The type of event this use case handles.
no setteroverride
- generator → UseCaseGenerator
-
Returns the existing use case instance or creates a new one if none exists.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialEventBuilder → UseCaseEventBuilder?
-
Optional builder for creating an initial event when the bloc starts.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- typeOfEvent → Type
-
The type of event this use case handles
final
- useCaseGenerator → UseCaseGenerator
-
Function that creates the use case instance
final
Methods
-
close(
) → Future< void> -
Closes and cleans up the use case instance.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited