action_bloc 0.0.2+1 copy "action_bloc: ^0.0.2+1" to clipboard
action_bloc: ^0.0.2+1 copied to clipboard

Extends bloc with a second stream for actions (one time events that aren't part of the state).

example/lib/main.dart

import 'package:action_bloc/action_bloc.dart';

// A cubit that counts up and emits FizzBuzz as actions
class CounterCubit extends ActionCubit<int, String> {
  CounterCubit() : super(0);

  void increment() {
    emit(state + 1);

    if (state % 15 == 0) {
      emitAction('FizzBuzz');
    } else if (state % 5 == 0) {
      emitAction('Buzz');
    } else if (state % 3 == 0) {
      emitAction('Fizz');
    } else {
      emitAction('$state');
    }
  }
}

Future<void> run(int limit) async {
  final cubit = CounterCubit();

  final actionSubscription = cubit.actions.listen(print);

  for (var i = 0; i < limit; i++) {
    cubit.increment();

    await Future<void>.delayed(const Duration(milliseconds: 250));
  }

  await actionSubscription.cancel();
  await cubit.close();
}
1
likes
140
pub points
0%
popularity

Publisher

unverified uploader

Extends bloc with a second stream for actions (one time events that aren't part of the state).

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (LICENSE)

Dependencies

bloc, meta

More

Packages that depend on action_bloc