import 'package:bloc/bloc.dart';

import 'message_event.dart';
import 'message_state.dart';

class MessageBloc extends Bloc<MessageEvent, MessageState> {
  MessageBloc() : super(MessageInitialState()) {
    on<MessageShow>(_show);
    on<MessageHide>(_hide);
  }

  void _show(MessageShow event, Emitter<MessageState> emit) async {
    emit(MessageShowState(message: event.message));
    await Future.delayed(event.duration);
    emit(MessageHideState());
  }

  void _hide(MessageHide event, Emitter<MessageState> emit) {
    emit(MessageHideState());
  }
}