AsyncCubitContainer class
A registry that AsyncCubit instances can register into.
Pass the same AsyncCubitContainer to multiple cubits so that one cubit
(e.g. a MutationCubit) can invalidate another (e.g. a FutureCubit)
after a successful mutation.
For simple apps a single shared registry is enough — use defaultContainer.
For more complex scenarios (e.g. feature modules with isolated lifecycles)
create separate AsyncCubitContainer instances.
Example:
// Both cubits share the same container (defaultInstance is used automatically).
BlocProvider(create: (_) => UserCubit(repository)),
BlocProvider(create: (_) => SaveUserCubit(repository)),
// Inside SaveUserCubit, call invalidate<T>() after a successful mutation:
class SaveUserCubit extends MutationCubit<User, void> {
SaveUserCubit(this._repository);
final UserRepository _repository;
@override
Future<void> mutation(User input) => _repository.saveUser(input);
@override
void onSuccess(void result) {
super.onSuccess(result);
invalidate<UserCubit>();
}
}
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
invalidate<
T extends FutureCubit> ({bool reload = false, InvalidateFilter< T> ? filter}) → Future<void> -
Invalidates all registered cubits of type
Tthat matchfilter. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
register(
FutureCubit cubit) → void -
Registers
cubitunder its runtime type. -
toString(
) → String -
A string representation of this object.
inherited
-
unregister(
FutureCubit cubit) → void -
Removes the registration for
cubit.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- defaultInstance → AsyncCubitContainer
-
A default shared container instance.
final