import 'package:flutter/foundation.dart'; 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/node_entity.dart'; import 'package:hadi_hoda_flutter/features/level/domain/entity/total_data_entity.dart'; import 'package:hive/hive.dart'; abstract class ILevelDatasource { Future> getLevels({required LevelParams params}); } /// Local class LocalLevelDatasourceImpl implements ILevelDatasource { const LocalLevelDatasourceImpl(); @override Future> getLevels({required LevelParams params}) async { try { final String selectedLanguage = LocalStorage.readData( key: MyConstants.selectLanguage) ?? MyConstants.defaultLanguage; final Box levelBox = Hive.box(MyConstants.levelBox); final TotalDataEntity findData = levelBox.values.firstWhere( (e) => e.code == selectedLanguage, orElse: () => TotalDataEntity(), ); debugPrint("nodesCount : ${findData.nodes?.first.level?.questions}"); return findData.nodes ?? []; } catch (e,s) { debugPrint(e.toString()); debugPrint(s.toString()); throw const MyException(errorMessage: 'Operation Failed'); } } }