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.
 
 
 
 

30 lines
1.0 KiB

import 'package:hadi_hoda_flutter/core/constants/my_constants.dart';
import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart';
import 'package:hadi_hoda_flutter/core/network/http_request.dart';
import 'package:hadi_hoda_flutter/core/params/question_params.dart';
import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart';
import 'package:hive/hive.dart';
abstract class IQuestionDatasource {
Future<LevelEntity> getLevel({required QuestionParams params});
}
class QuestionDatasourceImpl implements IQuestionDatasource {
final IHttpRequest httpRequest;
const QuestionDatasourceImpl(this.httpRequest);
@override
Future<LevelEntity> getLevel({required QuestionParams params}) async {
try {
final Box<LevelEntity> levelBox = Hive.box(MyConstants.levelBox);
final LevelEntity findLevel = levelBox.values.singleWhere(
(e) => e.id == params.id,
orElse: () => LevelEntity(),
);
return findLevel;
} catch (e) {
throw MyException(errorMessage: '$e');
}
}
}