0 purchases
disposable utils
disposable #
Provides a one abstract mechanism for releasing resources and utils for Dart and Flutter #
Did you notice there is no one defined method to release object resources in Dart and Flutter?
StreamController.close(), StreamSubscription.cancel() and many dispose() methods
in different Flutter object does the same - they free held information. But they doesn't have
any one defined interface for it. Disposable does it.
DisposableCollector is a composite of many disposables, which can be disposed as one.
It also provides extension methods to make life easier for streams.
Do you recognize it?
class SomeDisposable {
/// ...
final _subscription = someStream.listen(
(value) => doSomethingWith(value)
);
/// ...
void dispose() {
_subscription.cancel();
}
}
copied to clipboard
With DisposableCollector it will look like :
class SomeDisposable extends DisposableCollector {
/// ...
someStream
.listen((value) => doSomethingWith(value))
.addTo(this);
/// ...
}
copied to clipboard
And you can make Disposable from any of your objects with factory
final disposable = Disposable.create(yourObject, () => yourObject.close());
// or
final disposable = yourObject.toDisposable(() => yourObjectClose());
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.