Skip to content
pubscout

disposebag

1.5.1, released 4 years ago by an unverified publisher

Utility to collect and dispose StreamSubscriptions and Sinks in Dart/Flutter.

WASM-ready
$ flutter pub add disposebag
Source repository

What it does

DisposeBag lets you add StreamSubscriptions and Sinks and dispose them all at once. It provides extension methods for easy disposal and removal. Works on all Dart platforms.

AI-written summary of version 1.5.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You have multiple stream subscriptions or sinks that need coordinated cleanup
  • You want a lightweight way to avoid memory leaks in Flutter widgets
  • You prefer a simple API without additional dependencies

Skip it when

  • You need a full‑featured dependency‑injection or state‑management solution
  • You require code‑generation or advanced resource handling

Strengths

  • Very small and easy to understand
  • Null‑safe and works on all platforms
  • Extension methods make usage concise

Weaknesses

  • Only handles streams and sinks, no broader resource management
  • No built‑in logging configuration beyond a static logger

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
2
import 'package:disposebag/disposebag.dart';
import 'dart:async';

void main() async {
  final bag = DisposeBag([]);
  await Stream.value(1).listen(null).disposedBy(bag);
  await bag.dispose();
}

Alternatives

Packages that do the same job and could replace disposebag.

  • async

    Provides utilities like StreamQueue and other async helpers that can also help manage stream lifecycles

Works with

Packages commonly used together with disposebag: ones it builds on, ones built on it, and its own family.