BaseDelegate<S extends MainBlocState> mixin
Base delegate containing shared functionality between Bloc and Cubit.
This mixin provides common functionality for state management, loading indicators, and error handling that can be used by both Bloc and Cubit implementations.
Features:
- Loading state management via showLoading and hideLoading
- Navigation support via navigator
- Common bloc integration via commonBloc
- Error handling with catchError
Type Parameters:
S: The type of states. Must extend MainBlocState.
Usage with Bloc:
class MyBloc extends Bloc<MyEvent, MyState> with BaseDelegate<MyState> {
Future<void> handleAsyncOperation() async {
await catchError(
actions: () async {
showLoading(key: 'myOperation');
await someAsyncWork();
hideLoading(key: 'myOperation');
},
);
}
}
Usage with Cubit:
class MyCubit extends Cubit<MyState> with BaseDelegate<MyState> {
Future<void> handleAsyncOperation() async {
await catchError(
actions: () async {
showLoading();
await someAsyncWork();
hideLoading();
},
);
}
}
- Mixin applications
Properties
- commonBloc ↔ CommonBloc
-
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
catchError(
{required Future< void> actions(), bool isLoading = true, String keyLoading = LoadingKey.global, Future<void> onError(Object error, StackTrace stackTrace)?, Future<void> onFinally()?}) → Future<void> - Executes a given asynchronous action within a try-catch block, handling loading states.
-
dispose(
) → void -
hideLoading(
{String? key = LoadingKey.global}) → void - Hides the loading overlay for a specific key.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
showLoading(
{String? key = LoadingKey.global}) → void - Shows the loading overlay for a specific key.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited