// import 'dart:async'; import 'package:bytedesk_kefu/blocs/leavemsg_bloc/bloc.dart'; import 'package:bloc/bloc.dart'; import 'package:bytedesk_kefu/repositories/leavemsg_repository.dart'; import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; class LeaveMsgBloc extends Bloc { // final LeaveMsgRepository leaveMsgRepository = new LeaveMsgRepository(); LeaveMsgBloc() : super(new UnLeaveMsgState()) { on(_mapSubmitLeaveMsgToState); on(_mapUploadImageToState); } // @override // Stream mapEventToState( // LeaveMsgEvent event, // ) async* { // if (event is SubmitLeaveMsgEvent) { // yield* _mapSubmitLeaveMsgToState(event); // } else if (event is UploadImageEvent) { // yield* _mapUploadImageToState(event); // } // } void _mapSubmitLeaveMsgToState( SubmitLeaveMsgEvent event, Emitter emit) async { emit(LeaveMsgSubmiting()); try { await leaveMsgRepository.submitLeaveMsg(event.wid, event.aid, event.type, event.mobile, event.email, event.content); emit(LeaveMsgSubmitSuccessState()); } catch (error) { BytedeskUtils.printLog(error); emit(LeaveMsgSubmitError()); } } void _mapUploadImageToState( UploadImageEvent event, Emitter emit) async { emit(ImageUploading()); try { final String url = await leaveMsgRepository.upload(event.filePath); emit(UploadImageSuccess(url)); } catch (error) { BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } }