1import 'package:flutter_bloc/flutter_bloc.dart';
2import 'package:equatable/equatable.dart';
4import '../../../domain/repository/elearning_v2_repository.dart';
5import '../../../domain/entities/course_entity.dart';
6import '../../../domain/entities/qcm_entity.dart';
8part
'elearning_v2_state.dart';
10class ElearningV2Cubit
extends Cubit<ElearningV2State> {
13 ElearningV2Cubit(this._repository) : super(ElearningV2Initial());
17 emit(LoadingCoursesState());
20 final coursesResult = await
_repository.getCourses();
26 emit(CoursesLoadingFailureState(e.toString()));
32 emit(LoadingCourseDetailsState());
40 if (courseResult.isRight() &&
41 pdfPathResult.isRight() &&
42 qcmListResult.isRight()) {
43 final course = courseResult
44 .getOrElse(() =>
throw Exception(
"Failed to get course"));
46 .getOrElse(() =>
throw Exception(
"Failed to get PDF path"));
48 .getOrElse(() =>
throw Exception(
"Failed to get QCM list"));
53 String errorMessage =
"Failed to load course details";
54 if (courseResult.isLeft()) {
56 courseResult.fold((l) => l.message, (r) => errorMessage);
57 }
else if (pdfPathResult.isLeft()) {
59 pdfPathResult.fold((l) => l.message, (r) => errorMessage);
60 }
else if (qcmListResult.isLeft()) {
62 qcmListResult.fold((l) => l.message, (r) => errorMessage);
65 emit(CourseDetailsLoadingFailureState(errorMessage));
68 emit(CourseDetailsLoadingFailureState(e.toString()));
78 (
failure) => print(
'Failed to update progress: ${failure.message}'),
96 final updatedCourses = currentState.courses.map((
course) {
108 print(
'Failed to update progress: $e');
Future< void > updateProgress(int courseId, double progress) async
Future< void > loadCourseDetails(int courseId) async
final ElearningV2Repository _repository
ElearningV2Cubit(this._repository) Future< void > loadCourses() async
sealed class DocumentState extends Equatable failure
class CoursesLoadingFailureState extends ElearningV2State course
abstract class ElearningV2State extends Equatable courses
final List< QcmEntity > qcmList
const CourseDetailsLoadedState(this.course, this.pdfPath, this.qcmList)
const CoursesLoadedState(this.courses)
class GetPdfPathUseCase implements UseCase< String, PdfParams > courseId