Skip to content
pubscout

event_bus

2.0.1, released 2 years ago by jakobservices.ch

A lightweight event bus using Dart Streams for publish/subscribe communication

WASM-ready
$ flutter pub add event_bus
Source repository

What it does

It allows any Dart object to be fired as an event and listened to via streams. Listeners can filter by event type or listen to all events. It supports synchronous and asynchronous buses and custom stream controllers.

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

Use it when

  • You need a simple global event bus for decoupling components
  • You want to avoid complex state management libraries for small projects
  • You need to broadcast events across different parts of an app without tight coupling

Skip it when

  • You require advanced state management with reactive UI updates
  • You need dependency injection or service locator patterns
  • You are building a large-scale application that prefers a more structured architecture like BLoC or Redux

Strengths

  • Zero dependencies, MIT licensed
  • Supports both sync and async buses
  • Customizable with any StreamController
  • Simple API, easy to integrate

Weaknesses

  • No built-in lifecycle or cleanup management
  • Not a full state management solution
  • Can lead to hard-to-track event flows in large apps

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
0

Add dependency to pubspec and import package:event_bus/event_bus.dart

import 'package:event_bus/event_bus.dart';

final eventBus = EventBus();

class UserLoggedInEvent{final String user;UserLoggedInEvent(this.user);}

eventBus.on<UserLoggedInEvent>().listen((e)=>print(e.user));

eventBus.fire(UserLoggedInEvent('Alice'));

Alternatives

Packages that do the same job and could replace event_bus.

  • bloc

    Provides a more structured state management pattern with streams and events, suitable for larger apps

Works with

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