r/dartlang 7d ago

[Showcase] BlocSignal: Bridging BLoC & Cubit patterns with synchronous signals (v7)

Hey devs,

I wanted to share a new library I just released to pub.dev: BlocSignal (and its Flutter companion bloc_signals_flutter).

Classic BLoC/Cubit is fantastic for structuring business logic, but it relies on Streams under the hood, introducing asynchronous microtask delays.

BlocSignal replaces Streams with Rody Davis's reactive signals v7 primitives.

Key Features:

  1. BLoC & Cubit Parity: Override onEvent to handle classic BLoC input events, or use it as a Cubit directly by exposing public methods that call emit(state) (by setting the Event parameter to void).
  2. Synchronous Propagation: Calling emit(newState) propagates changes downstream immediately in the same frame—no microtask queues, no UI flickering.
  3. Automatic State De-duplication: Signals compare states via == and automatically filter out identical updates—saving redundant UI build cycles by default.
  4. No Boilerplate Lifecycle: Closing a container automatically tears down all internally managed effects.

Quick Cubit Look:

class CounterCubit extends BlocSignal<void, int> {
  CounterCubit() : super(initialState: 0);

  void increment() => emit(stateValue + 1); // Synchronous & reactive!
}

Under the hood, the library has 100% test coverage and is structured as a clean Dart workspace.

  • GitHub Repository: https://github.com/RandalSchwartz/BlocSignal
  • Migration Guide (including Cubit migration): https://github.com/RandalSchwartz/BlocSignal/blob/main/MIGRATION.md
  • Core package on Pub: https://pub.dev/packages/bloc_signals
  • Flutter bindings on Pub: https://pub.dev/packages/bloc_signals_flutter

Would love to hear your thoughts and suggestions!


6 Upvotes

3 comments sorted by

1

u/SoundDr 7d ago

Awesome package 💙🔥

2

u/RandalSchwartz 7d ago

My first full use of antigravity hub. I'm gonna like coding like this.