UseCase<TBloc extends JuiceBloc<BlocState> , TEvent extends EventBase> class
abstract
Base class for implementing use cases in the Juice framework.
A use case represents a single unit of business logic that can be executed in response to an event. It provides methods for emitting different types of state updates and handling navigation.
Type Parameters:
TBloc- The type of bloc this use case works withTEvent- The type of event this use case handles
Example:
class FetchUserUseCase extends UseCase<UserBloc, FetchUserEvent> {
@override
Future<void> execute(FetchUserEvent event) async {
try {
emitWaiting(); // Show loading state
final user = await userRepository.fetchUser(event.userId);
if (event is CancellableEvent && event.isCancelled) {
emitCancel(); // Show cancellation state
return;
}
emitUpdate(newState: UserState(user: user));
} catch (e) {
emitFailure(); // Show error state
}
}
}
- Implementers
Constructors
- UseCase()
Properties
- bloc ↔ TBloc
-
Reference to the bloc that owns this use case.
Set automatically by the framework via setBloc.
getter/setter pair
-
emitCancel
↔ void Function({Map<
String, dynamic> ? aviatorArgs, String? aviatorName, Set<String> ? groupsToRebuild, BlocState? newState}) -
Emits a cancellation state to indicate the operation was cancelled.
getter/setter pair
- emitEvent ↔ void Function({EventBase? event})
-
Emits a raw event without changing state.
getter/setter pair
-
emitFailure
↔ void Function({Map<
String, dynamic> ? aviatorArgs, String? aviatorName, Object? error, StackTrace? errorStackTrace, Set<String> ? groupsToRebuild, BlocState? newState}) -
Emits a failure state to indicate operation failure.
getter/setter pair
-
emitUpdate
↔ void Function({Map<
String, dynamic> ? aviatorArgs, String? aviatorName, Set<String> ? groupsToRebuild, BlocState? newState, bool skipIfSame}) -
Emits an update state to indicate successful operation completion.
getter/setter pair
-
emitWaiting
↔ void Function({Map<
String, dynamic> ? aviatorArgs, String? aviatorName, Set<String> ? groupsToRebuild, BlocState? newState}) -
Emits a waiting state to indicate operation in progress.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → void - Performs cleanup when the use case is no longer needed.
-
execute(
TEvent event) → Future< void> - Executes the business logic for this use case.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setBloc(
JuiceBloc< BlocState> blocInstance) → void - Sets the bloc reference for this use case.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited