https://github.com/felangel/broadcast_bloc
An extension to the bloc state management library which adds support for broadcasting state changes to stream channels.
https://github.com/felangel/broadcast_bloc
Last synced: 4 months ago
JSON representation
An extension to the bloc state management library which adds support for broadcasting state changes to stream channels.
- Host: GitHub
- URL: https://github.com/felangel/broadcast_bloc
- Owner: felangel
- License: mit
- Created: 2022-12-16T06:14:26.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-03T05:08:55.000Z (about 2 years ago)
- Last Synced: 2024-10-19T00:14:36.405Z (12 months ago)
- Language: Dart
- Homepage: https://pub.dev/packages/broadcast_bloc
- Size: 42 KB
- Stars: 17
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Broadcast Bloc
[![build][build_badge]][build_link]
[![coverage][coverage_badge]][build_link]
[![pub package][pub_badge]][pub_link]
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
[![License: MIT][license_badge]][license_link]An extension to the bloc state management library which adds support for broadcasting state changes to stream channels.
## Quick Start 🚀
```dart
// Extend `BroadcastCubit` instead of `Cubit`.
// The package also exports:
// * `BroadcastBloc`
// * `BroadcastMixin`
class CounterCubit extends BroadcastCubit {
CounterCubit() : super(0);void increment() => emit(state + 1);
}void main() {
final controller = StreamController(sync: true);
final subscription = controller.stream.listen(print);
final channel = StreamChannel(controller.stream, controller.sink);// Create an instance of the cubit.
final cubit = CounterCubit()
// Subscribe the channel.
..subscribe(channel)
// Trigger a state change which will be broadcast to subscribed channels.
..increment()
// Unsubscribe channel.
..unsubscribe(channel);subscription.cancel();
cubit.close();
}
```[build_badge]: https://github.com/felangel/broadcast_bloc/actions/workflows/main.yaml/badge.svg
[build_link]: https://github.com/felangel/broadcast_bloc/actions/workflows/main.yaml
[coverage_badge]: https://raw.githubusercontent.com/felangel/broadcast_bloc/main/coverage_badge.svg
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
[license_link]: https://opensource.org/licenses/MIT
[pub_badge]: https://img.shields.io/pub/v/broadcast_bloc.svg
[pub_link]: https://pub.dartlang.org/packages/broadcast_bloc
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis