9 changed files with 131 additions and 88 deletions
-
31lib/features/level/data/datasource/level_datasource.dart
-
10lib/features/level/data/model/level_model.dart
-
10lib/features/level/data/repository_impl/level_repository_impl.dart
-
4lib/features/level/domain/entity/level_location.dart
-
2lib/features/level/domain/repository/level_repository.dart
-
6lib/features/level/domain/usecases/get_level_usecase.dart
-
75lib/features/level/presentation/bloc/level_bloc.dart
-
2lib/features/level/presentation/bloc/level_event.dart
-
79lib/features/level/presentation/ui/level_page.dart
@ -1,28 +1,49 @@ |
|||
import 'package:hadi_hoda_flutter/core/constants/my_api.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/network/http_request.dart'; |
|||
import 'package:hadi_hoda_flutter/core/params/level_params.dart'; |
|||
import 'package:hadi_hoda_flutter/core/response/base_response.dart'; |
|||
import 'package:hadi_hoda_flutter/features/level/data/model/level_model.dart'; |
|||
import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart'; |
|||
import 'package:hive/hive.dart'; |
|||
|
|||
abstract class ILevelDatasource { |
|||
Future<LevelEntity> getData({required LevelParams params}); |
|||
Future<List<LevelEntity>> getLevels({required LevelParams params}); |
|||
} |
|||
|
|||
class LevelDatasourceImpl implements ILevelDatasource { |
|||
/// Remote |
|||
class RemoteLevelDatasourceImpl implements ILevelDatasource { |
|||
final IHttpRequest httpRequest; |
|||
|
|||
const LevelDatasourceImpl(this.httpRequest); |
|||
const RemoteLevelDatasourceImpl(this.httpRequest); |
|||
|
|||
@override |
|||
Future<LevelEntity> getData({required LevelParams params}) async { |
|||
Future<List<LevelEntity>> getLevels({required LevelParams params}) async { |
|||
final response = await httpRequest.get( |
|||
path: MyApi.baseUrl, |
|||
); |
|||
|
|||
return BaseResponse.getData<LevelEntity>( |
|||
return BaseResponse.getDataList<LevelEntity>( |
|||
response?['data'], |
|||
(json) => LevelModel.fromJson(json), |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
/// 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(); |
|||
} catch (_) { |
|||
throw MyException(errorMessage: 'Operation Failed'); |
|||
} |
|||
} |
|||
} |
@ -1,13 +1,23 @@ |
|||
import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart'; |
|||
import 'package:hadi_hoda_flutter/features/question/data/model/question_model.dart'; |
|||
import 'package:hadi_hoda_flutter/features/question/domain/entity/question_entity.dart'; |
|||
|
|||
class LevelModel extends LevelEntity { |
|||
LevelModel({ |
|||
super.id, |
|||
super.order, |
|||
super.title, |
|||
super.questions, |
|||
}); |
|||
|
|||
factory LevelModel.fromJson(Map<String, dynamic> json) { |
|||
return LevelModel( |
|||
id: json['id'], |
|||
order: json['order'], |
|||
title: json['title'], |
|||
questions: json['questions'] |
|||
?.map<QuestionEntity>((e) => QuestionModel.fromJson(e)) |
|||
.toList(), |
|||
); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue