2import 'package:flutter/services.dart';
3import 'package:shared_preferences/shared_preferences.dart';
5import '../models/course_model.dart';
6import '../models/qcm_model.dart';
7import '../../domain/entities/course_entity.dart';
8import '../../domain/entities/qcm_entity.dart';
9import 'elearning_v2_local_data_source.dart';
21 final String response =
22 await rootBundle.loadString(
'assets/data/courses.json');
23 final data = await json.decode(response) as List;
25 data.map((
course) => CourseModel.fromJson(
course)).toList();
28 for (var i = 0; i <
courses.length; i++) {
30 .getDouble(
'$_progressKeyPrefix${courses[i].id}') ??
36 description:
courses[i].description,
40 durationMinutes:
courses[i].durationMinutes,
43 createdAt:
courses[i].createdAt,
49 throw Exception(
'Failed to load courses: $e');
57 final String coursesResponse =
58 await rootBundle.loadString(
'assets/data/courses.json');
59 final coursesData = await json.decode(coursesResponse) as List;
60 final courseData = coursesData.firstWhere(
62 orElse: () =>
throw Exception(
'Course not found with ID: $courseId'),
64 final CourseModel
course = CourseModel.fromJson(courseData);
74 description:
course.description,
78 durationMinutes:
course.durationMinutes,
81 createdAt:
course.createdAt,
84 throw Exception(
'Failed to load course details: $e');
92 final String qcmResponse =
93 await rootBundle.loadString(
'assets/data/qcm.json');
94 final qcmData = await json.decode(qcmResponse) as List;
95 final courseQcm = qcmData
96 .where((qcm) => qcm[
'courseId'] ==
courseId)
97 .map((qcm) => QcmModel.fromJson(qcm))
100 if (courseQcm.isEmpty) {
107 throw Exception(
'Failed to load QCM questions: $e');
115 final String coursesResponse =
116 await rootBundle.loadString(
'assets/data/courses.json');
117 final coursesData = await json.decode(coursesResponse) as List;
118 final courseData = coursesData.firstWhere(
120 orElse: () =>
throw Exception(
'Course not found with ID: $courseId'),
122 final CourseModel
course = CourseModel.fromJson(courseData);
124 if (
course.pdfPath == null ||
course.pdfPath!.isEmpty) {
125 throw Exception(
'No PDF available for this course');
129 return 'assets/fonts/${course.pdfPath}';
131 throw Exception(
'Failed to get PDF path: $e');
140 throw Exception(
'Progress must be between 0.0 and 1.0');
145 '$_progressKeyPrefix$courseId',
progress);
148 throw Exception(
'Failed to update progress: $e');
override Future< String > getPdfPathForCourse(int courseId) async
override Future< List< QcmEntity > > getQcmForCourse(int courseId) async
static const String _progressKeyPrefix
final SharedPreferences sharedPreferences
override Future< bool > updateCourseProgress(int courseId, double progress) async
override Future< CourseEntity > getCourseDetails(int courseId) async
override Future< List< CourseEntity > > getCourses() async
ElearningV2LocalDataSourceImpl({required this.sharedPreferences})
class CoursesLoadingFailureState extends ElearningV2State course
abstract class ElearningV2State extends Equatable courses
class GetPdfPathUseCase implements UseCase< String, PdfParams > courseId