Skip to content
pubscout

comms

1.2.0, released 2 years ago by leancode.co

Stream-based communication pattern abstraction for decoupled messaging between classes and logic components.

WASM-ready
$ flutter pub add comms
Source repository

What it does

Provides mixins like Listener, Sender, MultiListener, and BLoC integrations (ListenerCubit, StateSender) that allow classes and state management components to broadcast and receive messages without passing explicit callbacks or stream references.

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

Use it when

  • You need decoupled communication between disparate BLoCs, Cubits, or non-UI logic classes.
  • You want to avoid manually wiring up and disposing of StreamControllers and StreamSubscriptions between controllers.

Skip it when

  • You prefer direct method calls or tightly coupled references for simplicity.
  • Your architecture does not use BLoC or stream-based patterns.

Strengths

  • Eliminates boilerplate code for connecting streams between logic classes.
  • Built-in support for BLoC and Cubit integration.
  • Supports initial message handling and covariant message types.

Weaknesses

  • Can obscure direct data flow and dependencies if overused across a large codebase.
  • Requires careful lifecycle management (calling cancel/dispose or using ListenerCubit).

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
3
class LightBulb with Listener<bool> {
  LightBulb() {
    listen();
  }

  bool enabled = false;
  
  @override
  void onMessage(bool message) {
    enabled = message;
  }

  void dispose() {
    cancel();
  }
}

class LightSwitch with Sender<bool> {
  void enable() {
    send(true);
  }
}

Alternatives

Packages that do the same job and could replace comms.

  • flutter_bloc

    Flutter widgets to easily integrate blocs and cubits for state management.

  • rxdart_ext

    Extension methods and classes built on top of RxDart like Single and StateStream.

  • rx_bloc

    A BLoC design pattern implementation using reactive streams.

  • result_command

    A command pattern implementation for Dart and Flutter using result_dart.

Works with

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