TIF_E41202535/lib/presentation/bloc/classification/classification_bloc.dart

66 lines
2.3 KiB
Dart

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<ClassificationEvent, ClassificationState> {
late ClassificationRepository _repository;
ClassificationBloc() : super(InitClassificationState()) {
_repository = ClassificationRepository.instance;
on<UploadClassification>((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<ResetClassification>((event, emit) async {
emit(ShowIdle());
});
}
}