You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

3 years ago
// import 'dart:async';
3 years ago
import 'package:bytedesk_kefu/blocs/feedback_bloc/bloc.dart';
import 'package:bytedesk_kefu/model/helpCategory.dart';
// import 'package:bytedesk_kefu/model/jsonResult.dart';
import 'package:bytedesk_kefu/repositories/feedback_repository.dart';
import 'package:bloc/bloc.dart';
class FeedbackBloc extends Bloc<FeedbackEvent, FeedbackState> {
//
final FeedbackRepository feedbackRepository = new FeedbackRepository();
3 years ago
FeedbackBloc() : super(new UnFeedbackState()) {
on<GetFeedbackCategoryEvent>(_mapGetFeedbackCategoryToState);
on<SubmitFeedbackEvent>(_mapSubmitFeedbackToState);
on<UploadImageEvent>(_mapUploadImageToState);
3 years ago
}
3 years ago
// @override
// void mapEventToState(
// FeedbackEvent event,
// ) async {
// if (event is GetFeedbackCategoryEvent) {
// yield* _mapGetFeedbackCategoryToState(event);
// } else if (event is SubmitFeedbackEvent) {
// yield* _mapSubmitFeedbackToState(event);
// } else if (event is UploadImageEvent) {
// yield* _mapUploadImageToState(event);
// }
// }
void _mapGetFeedbackCategoryToState(
GetFeedbackCategoryEvent event, Emitter<FeedbackState> emit) async {
emit(FeedbackLoading());
3 years ago
try {
final List<HelpCategory> categoryList =
await feedbackRepository.getHelpFeedbackCategories(event.uid);
3 years ago
emit(FeedbackCategoryState(categoryList));
3 years ago
} catch (error) {
print(error);
3 years ago
emit(FeedbackLoadError());
3 years ago
}
}
3 years ago
void _mapSubmitFeedbackToState(
SubmitFeedbackEvent event, Emitter<FeedbackState> emit) async {
emit(FeedbackSubmiting());
3 years ago
try {
await feedbackRepository.submitFeedback(event.content, event.imageUrls);
3 years ago
emit(FeedbackSubmitSuccess());
3 years ago
} catch (error) {
print(error);
3 years ago
emit(FeedbackSubmitError());
3 years ago
}
}
3 years ago
void _mapUploadImageToState(UploadImageEvent event, Emitter<FeedbackState> emit) async {
emit(ImageUploading());
3 years ago
try {
final String url = await feedbackRepository.upload(event.filePath);
3 years ago
emit(UploadImageSuccess(url));
3 years ago
} catch (error) {
print(error);
3 years ago
emit(UpLoadImageError());
3 years ago
}
}
}