import '../../../core/constant/glcm_type.dart'; import '../../../core/data/response/classification_response.dart'; import '../../../core/repository/classification_repository.dart'; import 'classification_event.dart'; import 'classification_state.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class ClassificationBloc extends Bloc { late ClassificationRepository _repository; ClassificationBloc() : super(InitClassificationState()) { _repository = ClassificationRepository.instance; on((event, emit) async { emit(ShowLoading()); var data = await _repository.uploadClassification( event.file, event.classificationType, event.cancerType); // var data = ClassificationResponse(data: 'wqeqweqew', assumption: ''); if (data.data.isNotEmpty) { String glcmType = all; if (event.classificationType == 'GLCM All + LVQ') { glcmType = all; } else if (event.classificationType == 'GLCM PCA + LVQ') { if (event.cancerType == 'Breast') { glcmType = pcaBreast; } else if (event.cancerType == 'Cervix') { glcmType = pcaCervix; } } else if (event.classificationType == 'GLCM regresi + LVQ') { if (event.cancerType == 'Breast') { glcmType = regressionBreast; } else if (event.cancerType == 'Cervix') { glcmType = regressionCervix; } } else if (event.classificationType == 'CNN') { if (event.cancerType == 'Breast') { glcmType = cnnBreast; } else if (event.cancerType == 'Cervix') { glcmType = cnnCervix; } } emit(ShowSuccessClassification( data: data.data, glcmType: glcmType, assumption: data.assumption, pattern: data.pattern, feature: data.feature, time: data.time, akurasi: data.akurasi, image: event.file, classificationType: event.classificationType, cancerType: event.cancerType )); } else { emit(ShowFailedClassification()); } }); on((event, emit) async { emit(ShowIdle()); }); } }