bloc_stream 5.0.0 copy "bloc_stream: ^5.0.0" to clipboard
bloc_stream: ^5.0.0 copied to clipboard

discontinued
outdated

A simple package that helps you to implement the BLoC pattern in your applications.

example/example.dart

import 'package:bloc_stream/bloc_stream.dart';

class CounterActions {
  static final Action<CounterBloc, int> increment =
      (bloc, add) async => add(bloc.value + 1);

  static final Action<CounterBloc, int> decrement =
      (bloc, add) async => add(bloc.value - 1);
}

class CounterBloc extends BlocStream<int> {
  CounterBloc() : super(0);
}

int multiplyByThree(int i) => i * 3;

class MultiplicationActions {
  static Action<MultiplicationBloc, int> multiply(input) =>
      (bloc, add) async => add(multiplyByThree(input));
}

class MultiplicationBloc extends BlocStream<int> {
  MultiplicationBloc(CounterBloc counter)
      : super(multiplyByThree(counter.value)) {
    // Bloc has a helper method for cleaning up subscriptions without having to
    // write a boilerplate close() override.
    cancelOnClose(counter.listen((count) {
      add(MultiplicationActions.multiply(count));
    }));
  }
}

void main() {
  final counter = CounterBloc();
  final multiplier = MultiplicationBloc(counter);

  // Prints:
  // 0
  // MULTIPLY 0
  // 1
  // 2
  // MULTIPLY 3
  // 3
  // MULTIPLY 6
  // 2
  // MULTIPLY 9
  // 1
  // MULTIPLY 6
  // MULTIPLY 3
  counter.listen(print);
  multiplier.listen((i) => print('MULTIPLY $i'));

  counter.add(CounterActions.increment);
  counter.add(CounterActions.increment);
  counter.add(CounterActions.increment);
  counter.add(CounterActions.decrement);
  counter.add(CounterActions.decrement);
}
3
likes
0
points
416
downloads

Publisher

verified publishertimsmart.co

Weekly Downloads

A simple package that helps you to implement the BLoC pattern in your applications.

Repository (GitLab)
View/report issues

License

unknown (license)

Dependencies

meta, rxdart

More

Packages that depend on bloc_stream