Skip to content
pubscout

stream_bloc

0.6.0, released a year ago by yakov.codes

A BLoC implementation that uses async generators to emit state streams.

WASM-ready
$ flutter pub add stream_bloc
Source repository

What it does

It provides a StreamBloc class that converts events into streams of states using mapEventToStates. The API is compatible with the official bloc package and can be used with flutter_bloc widgets. It also offers a BlocLifecycleMixin for stream-based Bloc-to-Bloc communication.

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

Use it when

  • You need generator-based event handling
  • You want to keep compatibility with bloc 8.x
  • You want to use stream transformers on events
  • You prefer a single method to emit multiple states

Skip it when

  • You prefer the newer on() pattern of bloc 8.x
  • You rely heavily on freezed-generated union types
  • You need the latest bloc features not yet merged

Strengths

  • Supports async generators for multiple state emissions
  • Compatible with flutter_bloc widgets
  • Allows native stream transformations
  • Provides lifecycle mixin for stream communication

Weaknesses

  • Older API, less documentation
  • May not support newest bloc features
  • Requires manual handling of identical states

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
2
class CounterEvent {}
class Increment implements CounterEvent {}
class Decrement implements CounterEvent {}
class StreamCounterBloc extends StreamBloc<CounterEvent, int> {
  StreamCounterBloc() : super(0);
  @override
  Stream<int> mapEventToStates(CounterEvent event) async* {
    if (event is Increment) yield state + 1;
    else if (event is Decrement) yield state - 1;
  }
}

Alternatives

Packages that do the same job and could replace stream_bloc.

Works with

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