bus 0.0.11

  • README.md
  • Installing
  • Versions
  • 54

Event Bus on Dart

A light-weight event bus library for Dart implementing the pub-sub pattern.

Functionality for JavaScript through dart2js is thanks to dart-patch-mirrors which provides some fixes for the buggy mirror functionality. All the examples provided work with dart2js.


Send a message to the bus and let the bus distribute the message to various handlers which are subscribed to that type of event. This library utilizes the Stream async library in Dart to handle subscriptions and publishing messages.


See pub.dartlang.org for instructions on how to use bus in your project.


A simple usage example:

import 'package:bus/bus.dart';

main() async {
  var bus = new Bus<String>();

  var sub = bus.subscribe((String message) {
    print('Received a string: "$message"');

  await bus.post('Hey there!');
  // cancel the subscription
  // the subscription was cancelled, this is pointless
  bus.post('This message will not be heard...');

Also supported is subscribing an object full of handlers:

class GameListener implements Listener {
  void _onGame(GameEvent event) {
    print('[An event occurred at ${event.timestamp}]');

  void _onChat(ChatEvent event) {
    print('${event.username} says "${event.message}"');


var bus = new Bus<GameEvent>();
var subs = bus.subscribeAll(new GameListener()); // returns a list of subscriptions

// remember to cancel your event subscriptions
subs.forEach((s) => s.cancel());

See the game example for explicit details.

For your synchronous needs, you can use SyncBus to publish and handle messages synchronously.

Features and bugs

Please file feature requests and bugs at the issue tracker.



  • Remove Listener.


  • Add tests (sync, async and listeners tests).


  • Getter for message type
  • Internal changes, util file for helpers


  • Synchronous bus, via new SyncBus<T>().


  • Documentation, README fixes.


  • Initial beta version.

Use this package as a library

1. Depend on it

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

  bus: "^0.0.11"

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:bus/bus.dart';
Version Uploaded Documentation Archive
0.0.11 Oct 17, 2017 Go to the documentation of bus 0.0.11 Download bus 0.0.11 archive
0.0.10 May 19, 2017 Go to the documentation of bus 0.0.10 Download bus 0.0.10 archive
0.0.9 May 19, 2017 Go to the documentation of bus 0.0.9 Download bus 0.0.9 archive
0.0.8 May 19, 2017 Go to the documentation of bus 0.0.8 Download bus 0.0.8 archive
0.0.7 May 19, 2017 Go to the documentation of bus 0.0.7 Download bus 0.0.7 archive
0.0.6 May 18, 2017 Go to the documentation of bus 0.0.6 Download bus 0.0.6 archive
0.0.5 May 18, 2017 Go to the documentation of bus 0.0.5 Download bus 0.0.5 archive
0.0.4 May 18, 2017 Go to the documentation of bus 0.0.4 Download bus 0.0.4 archive
0.0.3 May 18, 2017 Go to the documentation of bus 0.0.3 Download bus 0.0.3 archive
0.0.2 May 18, 2017 Go to the documentation of bus 0.0.2 Download bus 0.0.2 archive

All 11 versions...


We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
11 / 100
Code health derived from static analysis. [more]
96 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: web, other

Primary library: package:bus/bus.dart with components: mirrors.


  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 3 hints.

    Run dartfmt to format lib/src/bus.dart.

    Run dartfmt to format lib/src/handler.dart.

    Similar analysis of the following files failed:

    • lib/src/util.dart (hint)
  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use bus.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
patch_mirrors ^0.0.4 0.0.4
Dev dependencies
test ^0.12.0