scopedCubit<T extends Cubit> method
Defines a Cubit as scoped provider that will be automatically closed when the scope is closed.
The close
method of the Cubit instance created by the create
will be called when the scope is closed.
Defines the Cubit for a scope:
var blocModule = Module()
..scope<ScopeWidget>((scope) {
scope.scopedCubit<LoginCubit>((s) => LoginCubit());
});
Implementation
ProviderDefinition<T> scopedCubit<T extends Cubit>(
ProviderCreate<T> create, {
Qualifier qualifier,
bool createdAtStart = false,
bool override = false,
}) {
var beanDefinition =
scoped<T>(create, qualifier: qualifier, override: override);
beanDefinition.onClose((bloc) => bloc.close());
return beanDefinition;
}