Author: Petrus Nguyễn Thái Học
A package helps to cancel StreamSubscriptions and close Sinks.
How to easily cancel streams in Flutter
A simple usage example:
import 'package:disposebag/disposebag.dart';
import 'dart:async';
main() async {
final controllers = <StreamController>[];
final subscriptions = <StreamSubscription>[];
final bag = DisposeBag([...subscriptions, ...controllers]);
await Stream.value(3).listen(null).disposedBy(bag);
await StreamController<int>.broadcast().disposedBy(bag);
await StreamController<int>.broadcast(sync: true).disposedBy(bag);
await bag.dispose();
print("Bag disposed. It's all good");
}
Future<bool> DisposeBag.add(StreamSubscription);
Future<bool> DisposeBag.add(Sink);
Future<void> DisposeBag.addAll(Iterable<StreamSubscription>);
Future<void> DisposeBag.addAll(Iterable<Sink>);
// extension methods
Future<bool> StreamSubscription.disposedBy(DisposeBag);
Future<bool> Sink.disposedBy(DisposeBag);
Future<void> Iterable<StreamSubscription>.disposedBy(DisposeBag);
Future<void> Iterable<Sink>.disposedBy(DisposeBag);
bool delete(StreamSubscription);
bool delete(Sink);
Future<bool> remove(StreamSubscription);
Future<bool> remove(Sink);
Future<void> clear();
Future<void> dispose();
Please file feature requests and bugs at the issue tracker.