mirrored_repositories/bloc_flutter_template/lib/src
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_lib/src/events/counter_event.dart';

class CounterBloc extends Bloc<CounterEvent, int> {
  /// {@macro counter_bloc}
  CounterBloc() : super(0);

  @override
  Stream<int> mapEventToState(CounterEvent event) async* {
    switch (event) {
      case CounterEvent.decrement:
        yield state - 1;
        break;
      case CounterEvent.increment:
        yield state + 1;
        break;
      case CounterEvent.error:
        addError(Exception('unsupported event'));
    }
  }
}
