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.

64 lines
2.0 KiB

3 years ago
// import 'dart:async';
3 years ago
import 'package:bytedesk_kefu/blocs/ticket_bloc/bloc.dart';
import 'package:bloc/bloc.dart';
import 'package:bytedesk_kefu/repositories/ticket_repository.dart';
class TicketBloc extends Bloc<TicketEvent, TicketState> {
//
final TicketRepository feedbackRepository = new TicketRepository();
3 years ago
TicketBloc() : super(new UnTicketState()) {
on<GetTicketCategoryEvent>(_mapGetTicketCategoryToState);
on<SubmitTicketEvent>(_mapSubmitTicketToState);
on<UploadImageEvent>(_mapUploadImageToState);
3 years ago
}
3 years ago
// @override
// void mapEventToState(
// TicketEvent event,
// ) async* {
// if (event is GetTicketCategoryEvent) {
// yield* _mapGetTicketCategoryToState(event);
// } else if (event is SubmitTicketEvent) {
// yield* _mapSubmitTicketToState(event);
// } else if (event is UploadImageEvent) {
// yield* _mapUploadImageToState(event);
// }
// }
void _mapGetTicketCategoryToState(GetTicketCategoryEvent event, Emitter<TicketState> emit) async {
emit(TicketLoading());
3 years ago
try {
// final List<HelpCategory> categoryList =
// await feedbackRepository.getHelpTicketCategories();
3 years ago
// emit(TicketCategoryState(categoryList);
3 years ago
} catch (error) {
print(error);
3 years ago
emit(TicketLoadError());
3 years ago
}
}
3 years ago
void _mapSubmitTicketToState(SubmitTicketEvent event, Emitter<TicketState> emit) async {
emit(TicketLoading());
3 years ago
try {
// final List<HelpCategory> categoryList =
// await feedbackRepository.getHelpTicketCategories();
3 years ago
// emit(TicketCategoryState(categoryList);
3 years ago
} catch (error) {
print(error);
3 years ago
emit(TicketLoadError());
3 years ago
}
}
3 years ago
void _mapUploadImageToState(UploadImageEvent event, Emitter<TicketState> emit) async {
emit(TicketLoading());
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
}
}
}