simple_streams 1.1.0

  • Installing
  • Versions
  • 0

Simple Streams

Normal broadcast streams can be a pain. You have to keep track of all stream subscriptions manually, or there can be memory leaks. simple_streams makes it easier by keeping track of those subscriptions for you. Let's look at the standard dart way of using a broadcast stream versus with simple_streams.

Standard Dart Method (Bad)

First you must create a new broadcast StreamController and keep track of it's stream.

StreamController exampleStreamController = new StreamController.broadcast();
Stream exampleStream =;

Next, whenever you add a listener to the stream, you must manually keep track of the subscription.

exampleHandler(var e) {
StreamSubscription sub = exampleStream.listen(exampleHandler);

Finally, you must cancel the subscription when you are done with the stream. If you do not, you will get a memory leak.


Everytime you call .listen on that stream, it will create another StreamSubscription. You must keep track of all StreamSubscriptions and cancel all of them, otherwise you will create a memory leak. Or you can use simple streams to make it easier ;)

Simple Streams Method

Instead of creating a stream controller (and probably a separate variable to hold its stream), just create a simple stream.

SimpleStream exampleStream = new SimpleStream();

Next, you can add listeners as many times as you want without keeping track of their subscriptions.

exampleHandler(var e) {

Later, when you are done with the stream and it is going to be destroyed, call cancelAll() and it will cancel all of those subscriptions for you.



With version 1.1.0 of simple streams, a new class was introduced, SimpleStreamRouter. SimpleStreamRouter is just a wrapper that can be used with any pre-existing stream. For example, you may use it with a DivElement's onClick stream. It will do the same thing as a SimpleStream and keep track of the StreamSubscriptions for you.

SimpleStreamRouter router = new SimpleStreamRouter(querySelector('#example-element').onClick);

Listen to the router without keeping track of StreamSubscriptions. You will receive the same Event by listening to the router as you would to the element's stream itself.

exampleHandler(MouseEvent e) {
  print("do something");

When you are done with the router, you can call cancelAll() to avoid memory leaks.


Source code:

See the example in the test folder.

How to install:

Version 1.1.0:

  • Added SimpleStreamRouter
  • Switched to MIT LICENSE

Version 1.0.3:

  • Bug fix

Version 1.0.2:

  • Bug fix

Version 1.0.1:

  • Changed library name from simple_stream to simple_streams

Version 1.0.0:

  • Initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  simple_streams: ^1.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:simple_streams/simple_streams.dart';
Version Uploaded Documentation Archive
1.1.0 Jun 8, 2017 Go to the documentation of simple_streams 1.1.0 Download simple_streams 1.1.0 archive
1.0.3 Feb 22, 2017 Go to the documentation of simple_streams 1.0.3 Download simple_streams 1.0.3 archive
1.0.2 Feb 22, 2017 Go to the documentation of simple_streams 1.0.2 Download simple_streams 1.0.2 archive
1.0.1 Jan 19, 2017 Go to the documentation of simple_streams 1.0.1 Download simple_streams 1.0.1 archive
1.0.0 Jan 19, 2017 Go to the documentation of simple_streams 1.0.0 Download simple_streams 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.1.0.
 Because simple_streams depends on browser >=0.3.1+1 which requires SDK version <2.0.0, version solving failed.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

Package is getting outdated. (-50.41 points)

The package was released 78 weeks ago.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use simple_streams.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK any