broadcast_bloc
0.1.0, released a year ago by felangel.dev
Extends bloc to broadcast state changes to stream channels
What it does
Adds a BroadcastCubit and BroadcastBloc that can subscribe to StreamChannel objects. When the bloc emits a new state, all subscribed channels receive the state as a stream event.
AI-written summary of version 0.1.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- Need to expose bloc state to other parts of the app via streams
- Integrating with stream-based APIs or services
- Want multiple listeners to react to state changes without duplicating bloc instances
Skip it when
- Already using a different state‑management solution that provides broadcasting
- You don't need to share state via streams
Strengths
- Seamless integration with existing bloc code
- No additional code generation or build_runner steps
- Supports all platforms supported by bloc
Weaknesses
- Only works with bloc; not a drop‑in for other patterns
- Limited feature set beyond broadcasting
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
```dart
class CounterCubit extends BroadcastCubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
}
final controller = StreamController<String>(sync: true);
final subscription = controller.stream.listen(print);
final channel = StreamChannel(controller.stream, controller.sink);
final cubit = CounterCubit()
..subscribe(channel)
..increment()
..unsubscribe(channel);
subscription.cancel();
cubit.close();
```Alternatives
Packages that do the same job and could replace broadcast_bloc.
- yx_state
A state management library for Dart and Flutter applications.
82Compare - bloc_tools
Command-line tools for generating and linting bloc and cubit components.
88Compare - replay_bloc
Adds automatic undo and redo support to bloc and cubit states.
80Compare - bloc_signals_flutter
Flutter UI extensions, providers, and bindings for the bloc_signals state management library.
75Compare
Works with
Packages commonly used together with broadcast_bloc: ones it builds on, ones built on it, and its own family.