scopedDisposable<T extends Disposable> method
ProviderDefinition<T>
scopedDisposable<T extends Disposable>(})
Defines a BLoC as scoped definition
that will be automatically
closed when the scope is closed.
The dispose
method of the instance created by the definition
will
be called when the scope is closed.
Implement Disposable
interface when the business classes use streams
or it is necessary to finalize some internal component.
Implement the Disposable
interface:
class Bloc implements Disposable {
@override
void dispose() {
// close streams
// ...
}
}
Defines the bloc for a scope:
var blocModule = Module()
..scope<ScopeWidget>((scope) {
scope.scopedBloc<ScopedBloc>((s) => ScopedBloc());
});
Implementation
ProviderDefinition<T> scopedDisposable<T extends Disposable>(
ProviderCreate<T> create, {
Qualifier? qualifier,
bool createdAtStart = false,
bool override = false,
}) {
var beanDefinition =
scoped<T>(create, qualifier: qualifier, override: override);
beanDefinition.onClose((bloc) => bloc.dispose(),
onDisposeUnitialized: () {});
return beanDefinition;
}