From 9d60673e955de39fd17b16a03ed16dd1ee97b130 Mon Sep 17 00:00:00 2001 From: Aidaiym Date: Sat, 2 Mar 2024 16:28:11 -0800 Subject: [PATCH 1/7] change home architecture --- app/lib/app/view/app_view.dart | 8 ++- app/lib/models/models.dart | 2 - .../logic/hatim_read/hatim_read_cubit.dart | 2 - .../hatim/service/hatim_read_service.dart | 2 +- app/lib/modules/home/data/data.dart | 3 + .../home/data/model}/hatim_read_model.dart | 0 .../home/data/model}/hatim_read_model.g.dart | 0 .../home/data/repository/home_repository.dart | 24 +++++++ .../data/source/home_local_data_source.dart | 34 ++++++++++ .../data/source/home_remote_data_source.dart | 22 +++++++ app/lib/modules/home/data/source/source.dart | 2 + app/lib/modules/home/domain/domain.dart | 2 + .../modules/home/domain/entity/entity.dart | 1 + .../home/domain/entity}/home_model.dart | 0 .../home/domain/entity}/home_model.g.dart | 0 .../home/domain/usecase/get_data_usecase.dart | 10 +++ .../modules/home/domain/usecase/usecase.dart | 10 +++ app/lib/modules/home/home.dart | 8 +-- app/lib/modules/home/logic/home_cubit.dart | 19 ------ .../home/presentation/cubit/home_cubit.dart | 20 ++++++ .../cubit}/home_state.dart | 2 +- .../home/presentation/presentation.dart | 3 + .../{ => presentation}/view/home_view.dart | 0 .../{ => presentation}/widgets/home_card.dart | 0 .../modules/home/service/home_service.dart | 37 ----------- app/pubspec.lock | 64 +++++++++++++------ app/test/helpers/pump_app.dart | 4 +- app/test/widget_test.dart | 7 +- 28 files changed, 192 insertions(+), 94 deletions(-) create mode 100644 app/lib/modules/home/data/data.dart rename app/lib/{models/home => modules/home/data/model}/hatim_read_model.dart (100%) rename app/lib/{models/home => modules/home/data/model}/hatim_read_model.g.dart (100%) create mode 100644 app/lib/modules/home/data/repository/home_repository.dart create mode 100644 app/lib/modules/home/data/source/home_local_data_source.dart create mode 100644 app/lib/modules/home/data/source/home_remote_data_source.dart create mode 100644 app/lib/modules/home/data/source/source.dart create mode 100644 app/lib/modules/home/domain/domain.dart create mode 100644 app/lib/modules/home/domain/entity/entity.dart rename app/lib/{models/home => modules/home/domain/entity}/home_model.dart (100%) rename app/lib/{models/home => modules/home/domain/entity}/home_model.g.dart (100%) create mode 100644 app/lib/modules/home/domain/usecase/get_data_usecase.dart create mode 100644 app/lib/modules/home/domain/usecase/usecase.dart delete mode 100644 app/lib/modules/home/logic/home_cubit.dart create mode 100644 app/lib/modules/home/presentation/cubit/home_cubit.dart rename app/lib/modules/home/{logic => presentation/cubit}/home_state.dart (78%) create mode 100644 app/lib/modules/home/presentation/presentation.dart rename app/lib/modules/home/{ => presentation}/view/home_view.dart (100%) rename app/lib/modules/home/{ => presentation}/widgets/home_card.dart (100%) delete mode 100644 app/lib/modules/home/service/home_service.dart diff --git a/app/lib/app/view/app_view.dart b/app/lib/app/view/app_view.dart index 0907b13b..41b1d765 100644 --- a/app/lib/app/view/app_view.dart +++ b/app/lib/app/view/app_view.dart @@ -31,9 +31,11 @@ class MyApp extends StatelessWidget { ), BlocProvider( create: (context) => HomeCubit( - HomeService( - context.read(), - context.read(), + GetHomeDataUseCase( + HomeRepositoryImpl( + HomeLocalDataSource(context.read()), + HomeRemoteDataSource(context.read()), + ), ), ), ), diff --git a/app/lib/models/models.dart b/app/lib/models/models.dart index 8f815c92..48d01e63 100644 --- a/app/lib/models/models.dart +++ b/app/lib/models/models.dart @@ -1,6 +1,4 @@ export 'hatim/hatim_juz.dart'; -export 'home/home_model.dart'; -export 'home/hatim_read_model.dart'; export 'hatim/hatim_page.dart'; export 'juz/juz_data.dart'; export 'juz/juz_model.dart'; diff --git a/app/lib/modules/hatim/logic/hatim_read/hatim_read_cubit.dart b/app/lib/modules/hatim/logic/hatim_read/hatim_read_cubit.dart index 8bdcfda0..84614bf3 100644 --- a/app/lib/modules/hatim/logic/hatim_read/hatim_read_cubit.dart +++ b/app/lib/modules/hatim/logic/hatim_read/hatim_read_cubit.dart @@ -1,8 +1,6 @@ import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; - import 'package:my_quran/core/core.dart'; -import 'package:my_quran/models/models.dart'; import 'package:my_quran/modules/modules.dart'; part 'hatim_read_state.dart'; diff --git a/app/lib/modules/hatim/service/hatim_read_service.dart b/app/lib/modules/hatim/service/hatim_read_service.dart index 5a035b70..0af5f88e 100644 --- a/app/lib/modules/hatim/service/hatim_read_service.dart +++ b/app/lib/modules/hatim/service/hatim_read_service.dart @@ -1,6 +1,6 @@ import 'package:my_quran/config/config.dart'; import 'package:my_quran/core/core.dart'; -import 'package:my_quran/models/models.dart'; +import 'package:my_quran/modules/modules.dart'; class HatimReadService { const HatimReadService(this.client); diff --git a/app/lib/modules/home/data/data.dart b/app/lib/modules/home/data/data.dart new file mode 100644 index 00000000..6acee6e1 --- /dev/null +++ b/app/lib/modules/home/data/data.dart @@ -0,0 +1,3 @@ +export 'source/source.dart'; +export 'repository/home_repository.dart'; +export 'model/hatim_read_model.dart'; diff --git a/app/lib/models/home/hatim_read_model.dart b/app/lib/modules/home/data/model/hatim_read_model.dart similarity index 100% rename from app/lib/models/home/hatim_read_model.dart rename to app/lib/modules/home/data/model/hatim_read_model.dart diff --git a/app/lib/models/home/hatim_read_model.g.dart b/app/lib/modules/home/data/model/hatim_read_model.g.dart similarity index 100% rename from app/lib/models/home/hatim_read_model.g.dart rename to app/lib/modules/home/data/model/hatim_read_model.g.dart diff --git a/app/lib/modules/home/data/repository/home_repository.dart b/app/lib/modules/home/data/repository/home_repository.dart new file mode 100644 index 00000000..9ab476b9 --- /dev/null +++ b/app/lib/modules/home/data/repository/home_repository.dart @@ -0,0 +1,24 @@ +import 'dart:developer'; + +import 'package:my_quran/modules/modules.dart'; + +class HomeRepositoryImpl { + const HomeRepositoryImpl( + this.localDataSource, + this.remoteDataSource, + ); + + final HomeLocalDataSource localDataSource; + final HomeRemoteDataSource remoteDataSource; + + Future getData(String token) async { + try { + final remoteData = await remoteDataSource.getRemoteData(token); + await localDataSource.saveLocalData(remoteData); + return remoteData; + } catch (e) { + log('HomeRepositoryImpl, getData error: $e'); + return localDataSource.getLocalData(); + } + } +} diff --git a/app/lib/modules/home/data/source/home_local_data_source.dart b/app/lib/modules/home/data/source/home_local_data_source.dart new file mode 100644 index 00000000..44198380 --- /dev/null +++ b/app/lib/modules/home/data/source/home_local_data_source.dart @@ -0,0 +1,34 @@ +import 'dart:convert'; +import 'package:mq_storage/mq_storage.dart'; +import 'package:my_quran/modules/modules.dart'; + +class HomeLocalDataSource { + HomeLocalDataSource(this.storage); + + final PreferencesStorage storage; + HomeModel getLocalData() { + const key = 'home-model'; + final localValue = storage.readString(key: key); + if (localValue != null) { + final data = jsonDecode(localValue); + return HomeModel.fromJson(data as Map); + } else { + return const HomeModel(allDoneHatims: 0, allDonePages: 0, donePages: 0); + } + } + // Future getLocalData() async { + // const key = 'home-model'; + // final localValue = storage.readString(key: key); + // if (localValue != null) { + // final data = jsonDecode(localValue); + // return HomeModel.fromJson(data as Map); + // } else { + // return const HomeModel(allDoneHatims: 0, allDonePages: 0, donePages: 0); + // } + // } + + Future saveLocalData(HomeModel data) async { + const key = 'home-model'; + await storage.writeString(key: key, value: jsonEncode(data.toJson())); + } +} diff --git a/app/lib/modules/home/data/source/home_remote_data_source.dart b/app/lib/modules/home/data/source/home_remote_data_source.dart new file mode 100644 index 00000000..e4d5fe7d --- /dev/null +++ b/app/lib/modules/home/data/source/home_remote_data_source.dart @@ -0,0 +1,22 @@ +import 'package:my_quran/config/config.dart'; +import 'package:my_quran/core/core.dart'; +import 'package:my_quran/modules/modules.dart'; + +class HomeRemoteDataSource { + const HomeRemoteDataSource(this.remoteClient); + final RemoteClient remoteClient; + + Future getRemoteData(String token) async { + final remoteValue = await remoteClient.get( + apiConst.home, + fromJson: HomeModel.fromJson, + token: token, + ); + return remoteValue.fold( + (left) { + throw Exception('Failed to fetch remote data'); + }, + (right) => right, + ); + } +} diff --git a/app/lib/modules/home/data/source/source.dart b/app/lib/modules/home/data/source/source.dart new file mode 100644 index 00000000..b14165e6 --- /dev/null +++ b/app/lib/modules/home/data/source/source.dart @@ -0,0 +1,2 @@ +export 'home_local_data_source.dart'; +export 'home_remote_data_source.dart'; diff --git a/app/lib/modules/home/domain/domain.dart b/app/lib/modules/home/domain/domain.dart new file mode 100644 index 00000000..69a6aa8e --- /dev/null +++ b/app/lib/modules/home/domain/domain.dart @@ -0,0 +1,2 @@ +export 'usecase/usecase.dart'; +export 'entity/entity.dart'; diff --git a/app/lib/modules/home/domain/entity/entity.dart b/app/lib/modules/home/domain/entity/entity.dart new file mode 100644 index 00000000..99290e93 --- /dev/null +++ b/app/lib/modules/home/domain/entity/entity.dart @@ -0,0 +1 @@ +export 'home_model.dart'; diff --git a/app/lib/models/home/home_model.dart b/app/lib/modules/home/domain/entity/home_model.dart similarity index 100% rename from app/lib/models/home/home_model.dart rename to app/lib/modules/home/domain/entity/home_model.dart diff --git a/app/lib/models/home/home_model.g.dart b/app/lib/modules/home/domain/entity/home_model.g.dart similarity index 100% rename from app/lib/models/home/home_model.g.dart rename to app/lib/modules/home/domain/entity/home_model.g.dart diff --git a/app/lib/modules/home/domain/usecase/get_data_usecase.dart b/app/lib/modules/home/domain/usecase/get_data_usecase.dart new file mode 100644 index 00000000..b6d6925b --- /dev/null +++ b/app/lib/modules/home/domain/usecase/get_data_usecase.dart @@ -0,0 +1,10 @@ +import 'package:my_quran/modules/modules.dart'; + +class GetHomeDataUseCase { + GetHomeDataUseCase(this.repository); + final HomeRepositoryImpl repository; + + Future execute(String token) async { + return repository.getData(token); + } +} diff --git a/app/lib/modules/home/domain/usecase/usecase.dart b/app/lib/modules/home/domain/usecase/usecase.dart new file mode 100644 index 00000000..b6d6925b --- /dev/null +++ b/app/lib/modules/home/domain/usecase/usecase.dart @@ -0,0 +1,10 @@ +import 'package:my_quran/modules/modules.dart'; + +class GetHomeDataUseCase { + GetHomeDataUseCase(this.repository); + final HomeRepositoryImpl repository; + + Future execute(String token) async { + return repository.getData(token); + } +} diff --git a/app/lib/modules/home/home.dart b/app/lib/modules/home/home.dart index 8dfa66e6..200f0443 100644 --- a/app/lib/modules/home/home.dart +++ b/app/lib/modules/home/home.dart @@ -1,4 +1,4 @@ -export 'logic/home_cubit.dart'; -export 'view/home_view.dart'; -export 'widgets/home_card.dart'; -export 'service/home_service.dart'; +export 'presentation/presentation.dart'; +export 'data/repository/home_repository.dart'; +export 'data/data.dart'; +export 'domain/domain.dart'; diff --git a/app/lib/modules/home/logic/home_cubit.dart b/app/lib/modules/home/logic/home_cubit.dart deleted file mode 100644 index 1951578b..00000000 --- a/app/lib/modules/home/logic/home_cubit.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -import 'package:my_quran/core/core.dart'; -import 'package:my_quran/models/models.dart'; -import 'package:my_quran/modules/modules.dart'; - -part 'home_state.dart'; - -class HomeCubit extends Cubit { - HomeCubit(this.service) : super(const HomeState(FetchStatus.loading)); - - final HomeService service; - - Future getData(String token) async { - final homeModel = await service.getData(token); - emit(HomeState(FetchStatus.loading, homeModel: homeModel)); - } -} diff --git a/app/lib/modules/home/presentation/cubit/home_cubit.dart b/app/lib/modules/home/presentation/cubit/home_cubit.dart new file mode 100644 index 00000000..5116c833 --- /dev/null +++ b/app/lib/modules/home/presentation/cubit/home_cubit.dart @@ -0,0 +1,20 @@ +import 'package:equatable/equatable.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:my_quran/core/core.dart'; +import 'package:my_quran/modules/modules.dart'; + +part 'home_state.dart'; + +class HomeCubit extends Cubit { + HomeCubit(this.getHomeDataUseCase) : super(const HomeState(FetchStatus.loading)); + final GetHomeDataUseCase getHomeDataUseCase; + + Future getData(String token) async { + try { + final homeModel = await getHomeDataUseCase.execute(token); + emit(HomeState(FetchStatus.success, homeModel: homeModel)); + } catch (_) { + emit(const HomeState(FetchStatus.error)); + } + } +} diff --git a/app/lib/modules/home/logic/home_state.dart b/app/lib/modules/home/presentation/cubit/home_state.dart similarity index 78% rename from app/lib/modules/home/logic/home_state.dart rename to app/lib/modules/home/presentation/cubit/home_state.dart index 58f99251..71c6d94f 100644 --- a/app/lib/modules/home/logic/home_state.dart +++ b/app/lib/modules/home/presentation/cubit/home_state.dart @@ -7,5 +7,5 @@ class HomeState extends Equatable { final FetchStatus status; @override - List get props => [homeModel]; + List get props => [homeModel, status]; } diff --git a/app/lib/modules/home/presentation/presentation.dart b/app/lib/modules/home/presentation/presentation.dart new file mode 100644 index 00000000..e565a0a0 --- /dev/null +++ b/app/lib/modules/home/presentation/presentation.dart @@ -0,0 +1,3 @@ +export 'cubit/home_cubit.dart'; +export 'view/home_view.dart'; +export 'widgets/home_card.dart'; diff --git a/app/lib/modules/home/view/home_view.dart b/app/lib/modules/home/presentation/view/home_view.dart similarity index 100% rename from app/lib/modules/home/view/home_view.dart rename to app/lib/modules/home/presentation/view/home_view.dart diff --git a/app/lib/modules/home/widgets/home_card.dart b/app/lib/modules/home/presentation/widgets/home_card.dart similarity index 100% rename from app/lib/modules/home/widgets/home_card.dart rename to app/lib/modules/home/presentation/widgets/home_card.dart diff --git a/app/lib/modules/home/service/home_service.dart b/app/lib/modules/home/service/home_service.dart deleted file mode 100644 index b936c4a7..00000000 --- a/app/lib/modules/home/service/home_service.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'dart:convert'; - -import 'package:mq_storage/mq_storage.dart'; -import 'package:my_quran/config/config.dart'; -import 'package:my_quran/core/core.dart'; -import 'package:my_quran/models/models.dart'; - -class HomeService { - const HomeService(this.storage, this.remoteClient); - - final PreferencesStorage storage; - final RemoteClient remoteClient; - - Future getData(String token) async { - const key = 'home-model'; - final remoteValue = await remoteClient.get( - apiConst.home, - fromJson: HomeModel.fromJson, - token: token, - ); - return remoteValue.fold( - (l) async { - final localvalue = storage.readString(key: key); - if (localvalue != null) { - final data = jsonDecode(localvalue); - return HomeModel.fromJson(data as Map); - } else { - return const HomeModel(allDoneHatims: 0, allDonePages: 0, donePages: 0); - } - }, - (r) async { - await storage.writeString(key: key, value: jsonEncode(r.toJson())); - return r; - }, - ); - } -} diff --git a/app/pubspec.lock b/app/pubspec.lock index 2dcfd255..30dfd3a9 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -221,10 +221,10 @@ packages: dependency: transitive description: name: coverage - sha256: "595a29b55ce82d53398e1bcc2cba525d7bd7c59faeb2d2540e9d42c390cfeeeb" + sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" url: "https://pub.dev" source: hosted - version: "1.6.4" + version: "1.7.2" crypto: dependency: transitive description: @@ -317,10 +317,10 @@ packages: dependency: transitive description: name: file - sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" url: "https://pub.dev" source: hosted - version: "6.1.4" + version: "7.0.0" fixnum: dependency: transitive description: @@ -560,6 +560,30 @@ packages: url: "https://pub.dev" source: hosted version: "0.4.9" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" logging: dependency: transitive description: @@ -572,26 +596,26 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: "direct main" description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" mime: dependency: transitive description: @@ -682,10 +706,10 @@ packages: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" path_parsing: dependency: transitive description: @@ -754,10 +778,10 @@ packages: dependency: transitive description: name: platform - sha256: ae68c7bfcd7383af3629daafb32fb4e8681c7154428da4febcff06200585f102 + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" url: "https://pub.dev" source: hosted - version: "3.1.2" + version: "3.1.4" plugin_platform_interface: dependency: transitive description: @@ -778,10 +802,10 @@ packages: dependency: transitive description: name: process - sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09" + sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32" url: "https://pub.dev" source: hosted - version: "4.2.4" + version: "5.0.2" provider: dependency: transitive description: @@ -1223,10 +1247,10 @@ packages: dependency: transitive description: name: vm_service - sha256: c538be99af830f478718b51630ec1b6bee5e74e52c8a802d328d9e71d35d2583 + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "11.10.0" + version: "13.0.0" watcher: dependency: transitive description: @@ -1255,10 +1279,10 @@ packages: dependency: transitive description: name: webdriver - sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49" + sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e" url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.3" webkit_inspection_protocol: dependency: transitive description: diff --git a/app/test/helpers/pump_app.dart b/app/test/helpers/pump_app.dart index a2fc7c0c..c4bd8b25 100644 --- a/app/test/helpers/pump_app.dart +++ b/app/test/helpers/pump_app.dart @@ -10,7 +10,7 @@ extension PumpApp on WidgetTester { AppService appService, ThemeService themeService, AuthService authStorage, - HomeService homeService, + HomeRepositoryImpl homeService, ) { return pumpWidget( RepositoryProvider( @@ -19,7 +19,7 @@ extension PumpApp on WidgetTester { providers: [ BlocProvider(create: (context) => AppCubit(appService, themeService)), BlocProvider(create: (context) => AuthCubit(authStorage)), - BlocProvider(create: (context) => HomeCubit(homeService)), + BlocProvider(create: (context) => HomeCubit(GetHomeDataUseCase(homeService))), ], child: const QuranApp(), ), diff --git a/app/test/widget_test.dart b/app/test/widget_test.dart index 980a2637..3b0d86ef 100644 --- a/app/test/widget_test.dart +++ b/app/test/widget_test.dart @@ -6,7 +6,7 @@ import 'package:mq_storage/mq_storage.dart'; import 'package:my_quran/app/app.dart'; import 'package:my_quran/constants/contants.dart'; import 'package:my_quran/core/core.dart'; -import 'package:my_quran/modules/home/home.dart'; +import 'package:my_quran/modules/modules.dart'; import 'helpers/helpers.dart'; @@ -20,10 +20,11 @@ void main() { testWidgets('Punmp app', (WidgetTester tester) async { final storage = MockPreferencesStorage(); final remoteClient = MockRemoteClient(); - + final localDataSource = HomeLocalDataSource(storage); + final remoteDataSource = HomeRemoteDataSource(remoteClient); final appService = AppService(storage); final authStorage = AuthService(storage, remoteClient); - final homeService = HomeService(storage, remoteClient); + final homeService = HomeRepositoryImpl(localDataSource, remoteDataSource); final themeService = ThemeService(storage); when(() => storage.readString(key: AppConst.tokenKey)).thenReturn(null); From 21fa34c5f0d2fa50995f2f436975c735043995af Mon Sep 17 00:00:00 2001 From: Eldar2021 Date: Sat, 2 Mar 2024 23:39:53 +0600 Subject: [PATCH 2/7] Finish home clean architecture --- app/analysis_options.yaml | 1 + .../hatim}/hatim_read_model.dart | 0 .../hatim}/hatim_read_model.g.dart | 0 app/lib/models/models.dart | 1 + .../logic/hatim_read/hatim_read_cubit.dart | 1 + .../hatim/service/hatim_read_service.dart | 2 +- app/lib/modules/home/data/data.dart | 5 ++-- .../home/data/model/home_model_response.dart | 19 ++++++++++++ .../model/home_model_response.g.dart} | 6 ++-- .../home/data/repository/home_repository.dart | 15 ++++++++-- .../data/source/home_local_data_source.dart | 29 +++++++------------ .../data/source/home_remote_data_source.dart | 12 ++++---- app/lib/modules/home/data/source/source.dart | 2 -- app/lib/modules/home/domain/domain.dart | 3 +- .../modules/home/domain/entity/entity.dart | 1 - .../home/domain/entity/home_model.dart | 8 ----- .../domain/repository/home_repository.dart | 5 ++++ .../home/domain/usecase/get_data_usecase.dart | 5 ++-- .../modules/home/domain/usecase/usecase.dart | 5 ++-- .../home/presentation/cubit/home_cubit.dart | 7 +++-- .../home/presentation/cubit/home_state.dart | 5 +++- 21 files changed, 78 insertions(+), 54 deletions(-) rename app/lib/{modules/home/data/model => models/hatim}/hatim_read_model.dart (100%) rename app/lib/{modules/home/data/model => models/hatim}/hatim_read_model.g.dart (100%) create mode 100644 app/lib/modules/home/data/model/home_model_response.dart rename app/lib/modules/home/{domain/entity/home_model.g.dart => data/model/home_model_response.g.dart} (69%) delete mode 100644 app/lib/modules/home/data/source/source.dart delete mode 100644 app/lib/modules/home/domain/entity/entity.dart create mode 100644 app/lib/modules/home/domain/repository/home_repository.dart diff --git a/app/analysis_options.yaml b/app/analysis_options.yaml index 3cc70cd3..5ca25dd7 100644 --- a/app/analysis_options.yaml +++ b/app/analysis_options.yaml @@ -6,6 +6,7 @@ linter: sort_pub_dependencies: false lines_longer_than_80_chars: false directives_ordering: false + one_member_abstracts: false analyzer: exclude: diff --git a/app/lib/modules/home/data/model/hatim_read_model.dart b/app/lib/models/hatim/hatim_read_model.dart similarity index 100% rename from app/lib/modules/home/data/model/hatim_read_model.dart rename to app/lib/models/hatim/hatim_read_model.dart diff --git a/app/lib/modules/home/data/model/hatim_read_model.g.dart b/app/lib/models/hatim/hatim_read_model.g.dart similarity index 100% rename from app/lib/modules/home/data/model/hatim_read_model.g.dart rename to app/lib/models/hatim/hatim_read_model.g.dart diff --git a/app/lib/models/models.dart b/app/lib/models/models.dart index 48d01e63..83372aaa 100644 --- a/app/lib/models/models.dart +++ b/app/lib/models/models.dart @@ -1,5 +1,6 @@ export 'hatim/hatim_juz.dart'; export 'hatim/hatim_page.dart'; +export 'hatim/hatim_read_model.dart'; export 'juz/juz_data.dart'; export 'juz/juz_model.dart'; export 'juz/juz_surah_model.dart'; diff --git a/app/lib/modules/hatim/logic/hatim_read/hatim_read_cubit.dart b/app/lib/modules/hatim/logic/hatim_read/hatim_read_cubit.dart index 84614bf3..4f44b6f4 100644 --- a/app/lib/modules/hatim/logic/hatim_read/hatim_read_cubit.dart +++ b/app/lib/modules/hatim/logic/hatim_read/hatim_read_cubit.dart @@ -1,6 +1,7 @@ import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:my_quran/core/core.dart'; +import 'package:my_quran/models/models.dart'; import 'package:my_quran/modules/modules.dart'; part 'hatim_read_state.dart'; diff --git a/app/lib/modules/hatim/service/hatim_read_service.dart b/app/lib/modules/hatim/service/hatim_read_service.dart index 0af5f88e..5a035b70 100644 --- a/app/lib/modules/hatim/service/hatim_read_service.dart +++ b/app/lib/modules/hatim/service/hatim_read_service.dart @@ -1,6 +1,6 @@ import 'package:my_quran/config/config.dart'; import 'package:my_quran/core/core.dart'; -import 'package:my_quran/modules/modules.dart'; +import 'package:my_quran/models/models.dart'; class HatimReadService { const HatimReadService(this.client); diff --git a/app/lib/modules/home/data/data.dart b/app/lib/modules/home/data/data.dart index 6acee6e1..a71521b2 100644 --- a/app/lib/modules/home/data/data.dart +++ b/app/lib/modules/home/data/data.dart @@ -1,3 +1,4 @@ -export 'source/source.dart'; +export 'model/home_model_response.dart'; export 'repository/home_repository.dart'; -export 'model/hatim_read_model.dart'; +export 'source/home_local_data_source.dart'; +export 'source/home_remote_data_source.dart'; diff --git a/app/lib/modules/home/data/model/home_model_response.dart b/app/lib/modules/home/data/model/home_model_response.dart new file mode 100644 index 00000000..dc4fe334 --- /dev/null +++ b/app/lib/modules/home/data/model/home_model_response.dart @@ -0,0 +1,19 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'home_model_response.g.dart'; + +@JsonSerializable() +class HomeModelResponse { + const HomeModelResponse({ + required this.allDoneHatims, + required this.allDonePages, + required this.donePages, + }); + + factory HomeModelResponse.fromJson(Map json) => _$HomeModelResponseFromJson(json); + Map toJson() => _$HomeModelResponseToJson(this); + + final int allDoneHatims; + final int allDonePages; + final int donePages; +} diff --git a/app/lib/modules/home/domain/entity/home_model.g.dart b/app/lib/modules/home/data/model/home_model_response.g.dart similarity index 69% rename from app/lib/modules/home/domain/entity/home_model.g.dart rename to app/lib/modules/home/data/model/home_model_response.g.dart index ce00d364..43c97b0e 100644 --- a/app/lib/modules/home/domain/entity/home_model.g.dart +++ b/app/lib/modules/home/data/model/home_model_response.g.dart @@ -1,18 +1,18 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'home_model.dart'; +part of 'home_model_response.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -HomeModel _$HomeModelFromJson(Map json) => HomeModel( +HomeModelResponse _$HomeModelResponseFromJson(Map json) => HomeModelResponse( allDoneHatims: json['allDoneHatims'] as int, allDonePages: json['allDonePages'] as int, donePages: json['donePages'] as int, ); -Map _$HomeModelToJson(HomeModel instance) => { +Map _$HomeModelResponseToJson(HomeModelResponse instance) => { 'allDoneHatims': instance.allDoneHatims, 'allDonePages': instance.allDonePages, 'donePages': instance.donePages, diff --git a/app/lib/modules/home/data/repository/home_repository.dart b/app/lib/modules/home/data/repository/home_repository.dart index 9ab476b9..582acbae 100644 --- a/app/lib/modules/home/data/repository/home_repository.dart +++ b/app/lib/modules/home/data/repository/home_repository.dart @@ -2,7 +2,7 @@ import 'dart:developer'; import 'package:my_quran/modules/modules.dart'; -class HomeRepositoryImpl { +class HomeRepositoryImpl implements HomeRepository { const HomeRepositoryImpl( this.localDataSource, this.remoteDataSource, @@ -11,14 +11,23 @@ class HomeRepositoryImpl { final HomeLocalDataSource localDataSource; final HomeRemoteDataSource remoteDataSource; + @override Future getData(String token) async { try { final remoteData = await remoteDataSource.getRemoteData(token); await localDataSource.saveLocalData(remoteData); - return remoteData; + return _convertData(remoteData); } catch (e) { log('HomeRepositoryImpl, getData error: $e'); - return localDataSource.getLocalData(); + return _convertData(localDataSource.getLocalData()); } } + + HomeModel _convertData(HomeModelResponse response) { + return HomeModel( + allDoneHatims: response.allDoneHatims, + allDonePages: response.allDonePages, + donePages: response.donePages, + ); + } } diff --git a/app/lib/modules/home/data/source/home_local_data_source.dart b/app/lib/modules/home/data/source/home_local_data_source.dart index 44198380..8806c20e 100644 --- a/app/lib/modules/home/data/source/home_local_data_source.dart +++ b/app/lib/modules/home/data/source/home_local_data_source.dart @@ -3,32 +3,23 @@ import 'package:mq_storage/mq_storage.dart'; import 'package:my_quran/modules/modules.dart'; class HomeLocalDataSource { - HomeLocalDataSource(this.storage); + const HomeLocalDataSource(this.storage); final PreferencesStorage storage; - HomeModel getLocalData() { - const key = 'home-model'; - final localValue = storage.readString(key: key); + + static const _homeDataCacheKey = 'home-model'; + + HomeModelResponse getLocalData() { + final localValue = storage.readString(key: _homeDataCacheKey); if (localValue != null) { final data = jsonDecode(localValue); - return HomeModel.fromJson(data as Map); + return HomeModelResponse.fromJson(data as Map); } else { - return const HomeModel(allDoneHatims: 0, allDonePages: 0, donePages: 0); + return const HomeModelResponse(allDoneHatims: 0, allDonePages: 0, donePages: 0); } } - // Future getLocalData() async { - // const key = 'home-model'; - // final localValue = storage.readString(key: key); - // if (localValue != null) { - // final data = jsonDecode(localValue); - // return HomeModel.fromJson(data as Map); - // } else { - // return const HomeModel(allDoneHatims: 0, allDonePages: 0, donePages: 0); - // } - // } - Future saveLocalData(HomeModel data) async { - const key = 'home-model'; - await storage.writeString(key: key, value: jsonEncode(data.toJson())); + Future saveLocalData(HomeModelResponse data) async { + await storage.writeString(key: _homeDataCacheKey, value: jsonEncode(data.toJson())); } } diff --git a/app/lib/modules/home/data/source/home_remote_data_source.dart b/app/lib/modules/home/data/source/home_remote_data_source.dart index e4d5fe7d..64b7ef84 100644 --- a/app/lib/modules/home/data/source/home_remote_data_source.dart +++ b/app/lib/modules/home/data/source/home_remote_data_source.dart @@ -4,18 +4,18 @@ import 'package:my_quran/modules/modules.dart'; class HomeRemoteDataSource { const HomeRemoteDataSource(this.remoteClient); + final RemoteClient remoteClient; - Future getRemoteData(String token) async { - final remoteValue = await remoteClient.get( + Future getRemoteData(String token) async { + final remoteValue = await remoteClient.get( apiConst.home, - fromJson: HomeModel.fromJson, + fromJson: HomeModelResponse.fromJson, token: token, ); + return remoteValue.fold( - (left) { - throw Exception('Failed to fetch remote data'); - }, + (left) => throw Exception('Failed to fetch remote data $left'), (right) => right, ); } diff --git a/app/lib/modules/home/data/source/source.dart b/app/lib/modules/home/data/source/source.dart deleted file mode 100644 index b14165e6..00000000 --- a/app/lib/modules/home/data/source/source.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'home_local_data_source.dart'; -export 'home_remote_data_source.dart'; diff --git a/app/lib/modules/home/domain/domain.dart b/app/lib/modules/home/domain/domain.dart index 69a6aa8e..6e6675e3 100644 --- a/app/lib/modules/home/domain/domain.dart +++ b/app/lib/modules/home/domain/domain.dart @@ -1,2 +1,3 @@ export 'usecase/usecase.dart'; -export 'entity/entity.dart'; +export 'entity/home_model.dart'; +export 'repository/home_repository.dart'; diff --git a/app/lib/modules/home/domain/entity/entity.dart b/app/lib/modules/home/domain/entity/entity.dart deleted file mode 100644 index 99290e93..00000000 --- a/app/lib/modules/home/domain/entity/entity.dart +++ /dev/null @@ -1 +0,0 @@ -export 'home_model.dart'; diff --git a/app/lib/modules/home/domain/entity/home_model.dart b/app/lib/modules/home/domain/entity/home_model.dart index cb967e18..1fbac626 100644 --- a/app/lib/modules/home/domain/entity/home_model.dart +++ b/app/lib/modules/home/domain/entity/home_model.dart @@ -1,8 +1,3 @@ -import 'package:json_annotation/json_annotation.dart'; - -part 'home_model.g.dart'; - -@JsonSerializable() class HomeModel { const HomeModel({ required this.allDoneHatims, @@ -10,9 +5,6 @@ class HomeModel { required this.donePages, }); - factory HomeModel.fromJson(Map json) => _$HomeModelFromJson(json); - Map toJson() => _$HomeModelToJson(this); - final int allDoneHatims; final int allDonePages; final int donePages; diff --git a/app/lib/modules/home/domain/repository/home_repository.dart b/app/lib/modules/home/domain/repository/home_repository.dart new file mode 100644 index 00000000..c9792f31 --- /dev/null +++ b/app/lib/modules/home/domain/repository/home_repository.dart @@ -0,0 +1,5 @@ +import 'package:my_quran/modules/modules.dart'; + +abstract class HomeRepository { + Future getData(String token); +} diff --git a/app/lib/modules/home/domain/usecase/get_data_usecase.dart b/app/lib/modules/home/domain/usecase/get_data_usecase.dart index b6d6925b..d22ca2b2 100644 --- a/app/lib/modules/home/domain/usecase/get_data_usecase.dart +++ b/app/lib/modules/home/domain/usecase/get_data_usecase.dart @@ -1,10 +1,11 @@ import 'package:my_quran/modules/modules.dart'; class GetHomeDataUseCase { - GetHomeDataUseCase(this.repository); + const GetHomeDataUseCase(this.repository); + final HomeRepositoryImpl repository; - Future execute(String token) async { + Future execute(String token) { return repository.getData(token); } } diff --git a/app/lib/modules/home/domain/usecase/usecase.dart b/app/lib/modules/home/domain/usecase/usecase.dart index b6d6925b..06329100 100644 --- a/app/lib/modules/home/domain/usecase/usecase.dart +++ b/app/lib/modules/home/domain/usecase/usecase.dart @@ -1,8 +1,9 @@ import 'package:my_quran/modules/modules.dart'; class GetHomeDataUseCase { - GetHomeDataUseCase(this.repository); - final HomeRepositoryImpl repository; + const GetHomeDataUseCase(this.repository); + + final HomeRepository repository; Future execute(String token) async { return repository.getData(token); diff --git a/app/lib/modules/home/presentation/cubit/home_cubit.dart b/app/lib/modules/home/presentation/cubit/home_cubit.dart index 5116c833..7752b898 100644 --- a/app/lib/modules/home/presentation/cubit/home_cubit.dart +++ b/app/lib/modules/home/presentation/cubit/home_cubit.dart @@ -6,15 +6,16 @@ import 'package:my_quran/modules/modules.dart'; part 'home_state.dart'; class HomeCubit extends Cubit { - HomeCubit(this.getHomeDataUseCase) : super(const HomeState(FetchStatus.loading)); + HomeCubit(this.getHomeDataUseCase) : super(const HomeState()); + final GetHomeDataUseCase getHomeDataUseCase; Future getData(String token) async { try { final homeModel = await getHomeDataUseCase.execute(token); - emit(HomeState(FetchStatus.success, homeModel: homeModel)); + emit(HomeState(status: FetchStatus.success, homeModel: homeModel)); } catch (_) { - emit(const HomeState(FetchStatus.error)); + emit(const HomeState(status: FetchStatus.error)); } } } diff --git a/app/lib/modules/home/presentation/cubit/home_state.dart b/app/lib/modules/home/presentation/cubit/home_state.dart index 71c6d94f..4a26b219 100644 --- a/app/lib/modules/home/presentation/cubit/home_state.dart +++ b/app/lib/modules/home/presentation/cubit/home_state.dart @@ -1,7 +1,10 @@ part of 'home_cubit.dart'; class HomeState extends Equatable { - const HomeState(this.status, {this.homeModel}); + const HomeState({ + this.status = FetchStatus.loading, + this.homeModel, + }); final HomeModel? homeModel; final FetchStatus status; From 25972f17d09d11974d069f812e82ac98af74b7f8 Mon Sep 17 00:00:00 2001 From: Eldar2021 Date: Sat, 2 Mar 2024 23:42:58 +0600 Subject: [PATCH 3/7] Removed extra usecase (repeated) --- app/lib/modules/home/domain/domain.dart | 2 +- app/lib/modules/home/domain/usecase/usecase.dart | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 app/lib/modules/home/domain/usecase/usecase.dart diff --git a/app/lib/modules/home/domain/domain.dart b/app/lib/modules/home/domain/domain.dart index 6e6675e3..9b0a804f 100644 --- a/app/lib/modules/home/domain/domain.dart +++ b/app/lib/modules/home/domain/domain.dart @@ -1,3 +1,3 @@ -export 'usecase/usecase.dart'; +export 'usecase/get_data_usecase.dart'; export 'entity/home_model.dart'; export 'repository/home_repository.dart'; diff --git a/app/lib/modules/home/domain/usecase/usecase.dart b/app/lib/modules/home/domain/usecase/usecase.dart deleted file mode 100644 index 06329100..00000000 --- a/app/lib/modules/home/domain/usecase/usecase.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:my_quran/modules/modules.dart'; - -class GetHomeDataUseCase { - const GetHomeDataUseCase(this.repository); - - final HomeRepository repository; - - Future execute(String token) async { - return repository.getData(token); - } -} From 03ebb115fe9c9d395e319fdd83d726898d7b5bea Mon Sep 17 00:00:00 2001 From: Eldar2021 Date: Sat, 2 Mar 2024 23:45:18 +0600 Subject: [PATCH 4/7] Fixed exports (home module) --- app/lib/modules/home/domain/domain.dart | 2 +- app/lib/modules/home/home.dart | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/lib/modules/home/domain/domain.dart b/app/lib/modules/home/domain/domain.dart index 9b0a804f..41284c56 100644 --- a/app/lib/modules/home/domain/domain.dart +++ b/app/lib/modules/home/domain/domain.dart @@ -1,3 +1,3 @@ -export 'usecase/get_data_usecase.dart'; export 'entity/home_model.dart'; export 'repository/home_repository.dart'; +export 'usecase/get_data_usecase.dart'; diff --git a/app/lib/modules/home/home.dart b/app/lib/modules/home/home.dart index 200f0443..aeeb7088 100644 --- a/app/lib/modules/home/home.dart +++ b/app/lib/modules/home/home.dart @@ -1,4 +1,3 @@ -export 'presentation/presentation.dart'; -export 'data/repository/home_repository.dart'; export 'data/data.dart'; export 'domain/domain.dart'; +export 'presentation/presentation.dart'; From fa45d81b61a4bb1c673446a1d253b1795d078afb Mon Sep 17 00:00:00 2001 From: Eldar2021 Date: Sat, 2 Mar 2024 23:49:49 +0600 Subject: [PATCH 5/7] reverted pubspeck lock changes --- app/pubspec.lock | 66 +++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 45 deletions(-) diff --git a/app/pubspec.lock b/app/pubspec.lock index 30dfd3a9..5482a5f0 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -221,10 +221,10 @@ packages: dependency: transitive description: name: coverage - sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" + sha256: "595a29b55ce82d53398e1bcc2cba525d7bd7c59faeb2d2540e9d42c390cfeeeb" url: "https://pub.dev" source: hosted - version: "1.7.2" + version: "1.6.4" crypto: dependency: transitive description: @@ -317,10 +317,10 @@ packages: dependency: transitive description: name: file - sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" url: "https://pub.dev" source: hosted - version: "7.0.0" + version: "6.1.4" fixnum: dependency: transitive description: @@ -560,30 +560,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.4.9" - leak_tracker: - dependency: transitive - description: - name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" - url: "https://pub.dev" - source: hosted - version: "10.0.0" - leak_tracker_flutter_testing: - dependency: transitive - description: - name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 - url: "https://pub.dev" - source: hosted - version: "2.0.1" - leak_tracker_testing: - dependency: transitive - description: - name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 - url: "https://pub.dev" - source: hosted - version: "2.0.1" logging: dependency: transitive description: @@ -596,26 +572,26 @@ packages: dependency: transitive description: name: matcher - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" url: "https://pub.dev" source: hosted - version: "0.12.16+1" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.5.0" meta: dependency: "direct main" description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.10.0" mime: dependency: transitive description: @@ -706,10 +682,10 @@ packages: dependency: transitive description: name: path - sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" url: "https://pub.dev" source: hosted - version: "1.9.0" + version: "1.8.3" path_parsing: dependency: transitive description: @@ -778,10 +754,10 @@ packages: dependency: transitive description: name: platform - sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + sha256: ae68c7bfcd7383af3629daafb32fb4e8681c7154428da4febcff06200585f102 url: "https://pub.dev" source: hosted - version: "3.1.4" + version: "3.1.2" plugin_platform_interface: dependency: transitive description: @@ -802,10 +778,10 @@ packages: dependency: transitive description: name: process - sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32" + sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09" url: "https://pub.dev" source: hosted - version: "5.0.2" + version: "4.2.4" provider: dependency: transitive description: @@ -1247,10 +1223,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: c538be99af830f478718b51630ec1b6bee5e74e52c8a802d328d9e71d35d2583 url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "11.10.0" watcher: dependency: transitive description: @@ -1279,10 +1255,10 @@ packages: dependency: transitive description: name: webdriver - sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e" + sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.2" webkit_inspection_protocol: dependency: transitive description: @@ -1333,4 +1309,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.2.0 <4.0.0" - flutter: ">=3.16.9" + flutter: ">=3.16.9" \ No newline at end of file From 568e3c0912699851a616cb6b257838843850a8bb Mon Sep 17 00:00:00 2001 From: Eldar2021 Date: Sat, 2 Mar 2024 23:51:39 +0600 Subject: [PATCH 6/7] reverted pubspeck lock changes 02 --- app/pubspec.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pubspec.lock b/app/pubspec.lock index 5482a5f0..2dcfd255 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -1309,4 +1309,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.2.0 <4.0.0" - flutter: ">=3.16.9" \ No newline at end of file + flutter: ">=3.16.9" From 1f0496fa00bd0a557e4cf4d8e2a5734aec758b6e Mon Sep 17 00:00:00 2001 From: Eldar2021 Date: Sun, 3 Mar 2024 00:03:25 +0600 Subject: [PATCH 7/7] fixed tests --- .../home/domain/usecase/get_data_usecase.dart | 2 +- app/test/helpers/pump_app.dart | 4 ++-- app/test/widget_test.dart | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/lib/modules/home/domain/usecase/get_data_usecase.dart b/app/lib/modules/home/domain/usecase/get_data_usecase.dart index d22ca2b2..d0ce703f 100644 --- a/app/lib/modules/home/domain/usecase/get_data_usecase.dart +++ b/app/lib/modules/home/domain/usecase/get_data_usecase.dart @@ -3,7 +3,7 @@ import 'package:my_quran/modules/modules.dart'; class GetHomeDataUseCase { const GetHomeDataUseCase(this.repository); - final HomeRepositoryImpl repository; + final HomeRepository repository; Future execute(String token) { return repository.getData(token); diff --git a/app/test/helpers/pump_app.dart b/app/test/helpers/pump_app.dart index c4bd8b25..578ef63c 100644 --- a/app/test/helpers/pump_app.dart +++ b/app/test/helpers/pump_app.dart @@ -10,7 +10,7 @@ extension PumpApp on WidgetTester { AppService appService, ThemeService themeService, AuthService authStorage, - HomeRepositoryImpl homeService, + HomeRepository homeRepo, ) { return pumpWidget( RepositoryProvider( @@ -19,7 +19,7 @@ extension PumpApp on WidgetTester { providers: [ BlocProvider(create: (context) => AppCubit(appService, themeService)), BlocProvider(create: (context) => AuthCubit(authStorage)), - BlocProvider(create: (context) => HomeCubit(GetHomeDataUseCase(homeService))), + BlocProvider(create: (context) => HomeCubit(GetHomeDataUseCase(homeRepo))), ], child: const QuranApp(), ), diff --git a/app/test/widget_test.dart b/app/test/widget_test.dart index 3b0d86ef..49a7b73e 100644 --- a/app/test/widget_test.dart +++ b/app/test/widget_test.dart @@ -14,17 +14,22 @@ final class MockPreferencesStorage extends Mock implements PreferencesStorage {} final class MockRemoteClient extends Mock implements RemoteClient {} +final class MockHomeRepositoryImpl implements HomeRepository { + @override + Future getData(String token) async { + return const HomeModel(allDoneHatims: 8, allDonePages: 5325, donePages: 634); + } +} + // flutter test void main() { testWidgets('Punmp app', (WidgetTester tester) async { final storage = MockPreferencesStorage(); final remoteClient = MockRemoteClient(); - final localDataSource = HomeLocalDataSource(storage); - final remoteDataSource = HomeRemoteDataSource(remoteClient); final appService = AppService(storage); final authStorage = AuthService(storage, remoteClient); - final homeService = HomeRepositoryImpl(localDataSource, remoteDataSource); + final homeRepo = MockHomeRepositoryImpl(); final themeService = ThemeService(storage); when(() => storage.readString(key: AppConst.tokenKey)).thenReturn(null); @@ -33,8 +38,7 @@ void main() { when(() => storage.readString(key: AppConst.modeKey)).thenReturn(null); when(() => storage.readString(key: AppConst.colorKey)).thenReturn(null); - // // Build our app and trigger a frame. - await tester.pumpApp(appService, themeService, authStorage, homeService); + await tester.pumpApp(appService, themeService, authStorage, homeRepo); await tester.pumpAndSettle(); expect(find.byType(MaterialApp), findsOneWidget); });