stream_bloc 0.5.0 copy "stream_bloc: ^0.5.0" to clipboard
stream_bloc: ^0.5.0 copied to clipboard

outdated

Modern implementation of the Original BLoC that uses asynchronous generators to describe relationships between events and states.

example/main.dart

// ignore_for_file: avoid_print

import 'package:stream_bloc/stream_bloc.dart';

abstract class CounterEvent {}

class Increment implements CounterEvent {}

class Decrement implements CounterEvent {}

class CounterBloc extends StreamBloc<CounterEvent, int> {
  CounterBloc() : super(0);

  @override
  Stream<int> mapEventToStates(CounterEvent event) async* {
    if (event is Increment) {
      yield state + 1;
    } else if (event is Decrement) {
      yield state - 1;
    }
  }
}

Future<void> main(List<String> arguments) async {
  final bloc = CounterBloc();

  final printSubscription = bloc.stream.listen(print);

  bloc
    ..add(Increment())
    ..add(Increment())
    ..add(Increment())
    ..add(Decrement());
  await Future<void>.delayed(Duration.zero);

  await printSubscription.cancel();
  await bloc.close();
}
36
likes
0
pub points
83%
popularity

Publisher

verified publisheryakov.codes

Modern implementation of the Original BLoC that uses asynchronous generators to describe relationships between events and states.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

bloc, meta

More

Packages that depend on stream_bloc