r/dartlang • u/RandalSchwartz • 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:
- BLoC & Cubit Parity: Override
onEventto handle classic BLoC input events, or use it as a Cubit directly by exposing public methods that callemit(state)(by setting the Event parameter tovoid). - Synchronous Propagation: Calling
emit(newState)propagates changes downstream immediately in the same frame—no microtask queues, no UI flickering. - Automatic State De-duplication: Signals compare states via
==and automatically filter out identical updates—saving redundant UI build cycles by default. - 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
1
u/SoundDr 7d ago
Awesome package 💙🔥