|
|
@ -1,7 +1,9 @@ |
|
|
|
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/params/level_params.dart'; |
|
|
|
import 'package:hadi_hoda_flutter/core/utils/local_storage.dart'; |
|
|
|
import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart'; |
|
|
|
import 'package:hadi_hoda_flutter/features/level/domain/entity/total_data_entity.dart'; |
|
|
|
import 'package:hive/hive.dart'; |
|
|
|
|
|
|
|
abstract class ILevelDatasource { |
|
|
@ -10,14 +12,19 @@ abstract class ILevelDatasource { |
|
|
|
|
|
|
|
/// Local |
|
|
|
class LocalLevelDatasourceImpl implements ILevelDatasource { |
|
|
|
|
|
|
|
const LocalLevelDatasourceImpl(); |
|
|
|
|
|
|
|
@override |
|
|
|
Future<List<LevelEntity>> getLevels({required LevelParams params}) async { |
|
|
|
try { |
|
|
|
final Box<LevelEntity> levelBox = Hive.box(MyConstants.levelBox); |
|
|
|
return levelBox.values.toList(); |
|
|
|
final String selectedLanguage = LocalStorage.readData( |
|
|
|
key: MyConstants.selectLanguage); |
|
|
|
final Box<TotalDataEntity> levelBox = Hive.box(MyConstants.levelBox); |
|
|
|
final TotalDataEntity findData = levelBox.values.singleWhere((e) => |
|
|
|
e.code == selectedLanguage, |
|
|
|
orElse: () => TotalDataEntity(), |
|
|
|
); |
|
|
|
return findData.levels ?? []; |
|
|
|
} catch (_) { |
|
|
|
throw MyException(errorMessage: 'Operation Failed'); |
|
|
|
} |
|
|
|