import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/interactors/timer_interactor.dart'; import 'package:lightmeter/screens/timer/event_timer.dart'; import 'package:lightmeter/screens/timer/state_timer.dart'; class TimerBloc extends Bloc { final TimerInteractor _timerInteractor; final Duration duration; TimerBloc(this._timerInteractor, this.duration) : super(const TimerStoppedState()) { on(_onStartTimer); on(_onTimerEnded); on(_onStopTimer); on(_onResetTimer); if (_timerInteractor.isAutostartTimerEnabled) add(const StartTimerEvent()); } Future _onStartTimer(StartTimerEvent _, Emitter emit) async { _timerInteractor.quickVibration(); emit(const TimerResumedState()); } Future _onTimerEnded(TimerEndedEvent event, Emitter emit) async { if (state is! TimerResetState) { _timerInteractor.responseVibration(); emit(const TimerStoppedState()); } } Future _onStopTimer(StopTimerEvent _, Emitter emit) async { _timerInteractor.quickVibration(); emit(const TimerStoppedState()); } Future _onResetTimer(ResetTimerEvent _, Emitter emit) async { emit(const TimerResetState()); } }