diff --git a/lib/common_ui/resources/my_assets.dart b/lib/common_ui/resources/my_assets.dart index 862e6a3..aa38b53 100644 --- a/lib/common_ui/resources/my_assets.dart +++ b/lib/common_ui/resources/my_assets.dart @@ -3,7 +3,7 @@ class MyAssets { const MyAssets._internal(); factory MyAssets() => _i; - static const String backgroundIntro = 'assets/images/background_intro.png'; + static const String backgroundHome = 'assets/images/background_intro.png'; static const String closeBtn = 'assets/images/close_btn.svg'; static const String hadiHoda = 'assets/images/hadi_hoda.png'; static const String musicOff = 'assets/images/music_off.svg'; diff --git a/lib/core/middleware/auth_middleware.dart b/lib/core/middleware/auth_middleware.dart index 16064ec..a6901af 100644 --- a/lib/core/middleware/auth_middleware.dart +++ b/lib/core/middleware/auth_middleware.dart @@ -12,7 +12,7 @@ class AuthMiddleware { static FutureOr redirect(BuildContext context, GoRouterState state) async { if (AuthStorage.isLogin()) { - return Routes.introPage; + return Routes.homePage; } else { return null; } diff --git a/lib/core/params/home_params.dart b/lib/core/params/home_params.dart new file mode 100644 index 0000000..fdd3091 --- /dev/null +++ b/lib/core/params/home_params.dart @@ -0,0 +1,13 @@ +class HomeParams { + int? id; + + HomeParams({this.id}); + + HomeParams copyWith({ + int? id, + }) { + return HomeParams( + id: id ?? this.id, + ); + } +} diff --git a/lib/core/params/intro_params.dart b/lib/core/params/intro_params.dart deleted file mode 100644 index e03d91f..0000000 --- a/lib/core/params/intro_params.dart +++ /dev/null @@ -1,13 +0,0 @@ -class IntroParams { - int? id; - - IntroParams({this.id}); - - IntroParams copyWith({ - int? id, - }) { - return IntroParams( - id: id ?? this.id, - ); - } -} diff --git a/lib/core/routers/my_routes.dart b/lib/core/routers/my_routes.dart index da88851..d17eb0f 100644 --- a/lib/core/routers/my_routes.dart +++ b/lib/core/routers/my_routes.dart @@ -1,8 +1,8 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import 'package:hadi_hoda_flutter/core/utils/context_provider.dart'; -import 'package:hadi_hoda_flutter/features/intro/presentation/bloc/intro_bloc.dart'; -import 'package:hadi_hoda_flutter/features/intro/presentation/ui/intro_page.dart'; +import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_bloc.dart'; +import 'package:hadi_hoda_flutter/features/home/presentation/ui/home_page.dart'; import 'package:hadi_hoda_flutter/features/level/presentation/bloc/level_bloc.dart'; import 'package:hadi_hoda_flutter/features/level/presentation/ui/level_page.dart'; import 'package:hadi_hoda_flutter/features/question/presentation/bloc/question_bloc.dart'; @@ -14,21 +14,21 @@ class Routes { const Routes._internal(); factory Routes() => _i; - static const String introPage = '/intro_page'; + static const String homePage = '/home_page'; static const String questionPage = '/question_page'; static const String levelPage = '/level_page'; } GoRouter get appPages => GoRouter( - initialLocation: Routes.introPage, + initialLocation: Routes.homePage, navigatorKey: ContextProvider.navigatorKey, routes: [ GoRoute( - name: Routes.introPage, - path: Routes.introPage, + name: Routes.homePage, + path: Routes.homePage, builder: (context, state) => BlocProvider( - create: (context) => IntroBloc(locator()), - child: const IntroPage(), + create: (context) => HomeBloc(locator()), + child: const HomePage(), ), ), GoRoute( diff --git a/lib/core/widgets/answer_box/styles/picture_box.dart b/lib/core/widgets/answer_box/styles/picture_box.dart index 1b9ab51..a6e62c8 100644 --- a/lib/core/widgets/answer_box/styles/picture_box.dart +++ b/lib/core/widgets/answer_box/styles/picture_box.dart @@ -20,7 +20,7 @@ class AnswerPictureBox extends StatelessWidget { child: Stack( children: [ MyImage( - image: MyAssets.backgroundIntro, + image: MyAssets.backgroundHome, fit: BoxFit.cover, size: 170, ), diff --git a/lib/features/home/data/datasource/home_datasource.dart b/lib/features/home/data/datasource/home_datasource.dart new file mode 100644 index 0000000..17db1cf --- /dev/null +++ b/lib/features/home/data/datasource/home_datasource.dart @@ -0,0 +1,28 @@ +import 'package:hadi_hoda_flutter/core/constants/my_api.dart'; +import 'package:hadi_hoda_flutter/core/network/http_request.dart'; +import 'package:hadi_hoda_flutter/core/params/home_params.dart'; +import 'package:hadi_hoda_flutter/core/response/base_response.dart'; +import 'package:hadi_hoda_flutter/features/home/data/model/home_model.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/entity/home_entity.dart'; + +abstract class IHomeDatasource { + Future getData({required HomeParams params}); +} + +class HomeDatasourceImpl implements IHomeDatasource { + final IHttpRequest httpRequest; + + const HomeDatasourceImpl(this.httpRequest); + + @override + Future getData({required HomeParams params}) async { + final response = await httpRequest.get( + path: MyApi.baseUrl, + ); + + return BaseResponse.getData( + response?['data'], + (json) => HomeModel.fromJson(json), + ); + } +} diff --git a/lib/features/home/data/model/home_model.dart b/lib/features/home/data/model/home_model.dart new file mode 100644 index 0000000..c63431f --- /dev/null +++ b/lib/features/home/data/model/home_model.dart @@ -0,0 +1,13 @@ +import 'package:hadi_hoda_flutter/features/home/domain/entity/home_entity.dart'; + +class HomeModel extends HomeEntity { + const HomeModel({ + super.id, + }); + + factory HomeModel.fromJson(Map json) { + return HomeModel( + id: json['id'], + ); + } +} diff --git a/lib/features/home/data/repository_impl/home_repository_impl.dart b/lib/features/home/data/repository_impl/home_repository_impl.dart new file mode 100644 index 0000000..594969b --- /dev/null +++ b/lib/features/home/data/repository_impl/home_repository_impl.dart @@ -0,0 +1,29 @@ +import 'package:hadi_hoda_flutter/core/params/home_params.dart'; +import 'package:flutter/foundation.dart'; +import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart'; +import 'package:hadi_hoda_flutter/core/utils/data_state.dart'; +import 'package:hadi_hoda_flutter/features/home/data/datasource/home_datasource.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/entity/home_entity.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/repository/home_repository.dart'; + +class HomeRepositoryImpl implements IHomeRepository { + final IHomeDatasource datasource; + + const HomeRepositoryImpl(this.datasource); + + @override + Future> getData({required HomeParams params}) async { + try { + final HomeEntity response = await datasource.getData(params: params); + return DataState.success(response); + } on MyException catch (e) { + return DataState.error(e); + } catch (e) { + if (kDebugMode) { + rethrow; + } else { + return DataState.error(MyException(errorMessage: '$e')); + } + } + } +} diff --git a/lib/features/intro/domain/entity/intro_entity.dart b/lib/features/home/domain/entity/home_entity.dart similarity index 71% rename from lib/features/intro/domain/entity/intro_entity.dart rename to lib/features/home/domain/entity/home_entity.dart index 15c2e44..582723c 100644 --- a/lib/features/intro/domain/entity/intro_entity.dart +++ b/lib/features/home/domain/entity/home_entity.dart @@ -1,9 +1,9 @@ import 'package:equatable/equatable.dart'; -class IntroEntity extends Equatable { +class HomeEntity extends Equatable { final int? id; - const IntroEntity({ + const HomeEntity({ this.id, }); diff --git a/lib/features/home/domain/repository/home_repository.dart b/lib/features/home/domain/repository/home_repository.dart new file mode 100644 index 0000000..81ad27c --- /dev/null +++ b/lib/features/home/domain/repository/home_repository.dart @@ -0,0 +1,8 @@ +import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart'; +import 'package:hadi_hoda_flutter/core/params/home_params.dart'; +import 'package:hadi_hoda_flutter/core/utils/data_state.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/entity/home_entity.dart'; + +abstract class IHomeRepository { + Future> getData({required HomeParams params}); +} diff --git a/lib/features/home/domain/usecases/get_home_usecase.dart b/lib/features/home/domain/usecases/get_home_usecase.dart new file mode 100644 index 0000000..cbb629d --- /dev/null +++ b/lib/features/home/domain/usecases/get_home_usecase.dart @@ -0,0 +1,17 @@ +import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart'; +import 'package:hadi_hoda_flutter/core/params/home_params.dart'; +import 'package:hadi_hoda_flutter/core/usecase/usecase.dart'; +import 'package:hadi_hoda_flutter/core/utils/data_state.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/entity/home_entity.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/repository/home_repository.dart'; + +class GetHomeUseCase implements UseCase { + final IHomeRepository repository; + + const GetHomeUseCase(this.repository); + + @override + Future> call(HomeParams params) { + return repository.getData(params: params); + } +} diff --git a/lib/features/home/presentation/bloc/home_bloc.dart b/lib/features/home/presentation/bloc/home_bloc.dart new file mode 100644 index 0000000..ae5f8ec --- /dev/null +++ b/lib/features/home/presentation/bloc/home_bloc.dart @@ -0,0 +1,41 @@ +import 'dart:async'; +import 'package:bloc/bloc.dart'; +import 'package:hadi_hoda_flutter/core/status/base_status.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/entity/home_entity.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/usecases/get_home_usecase.dart'; +import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_event.dart'; +import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_state.dart'; + +class HomeBloc extends Bloc { + /// ------------constructor------------ + HomeBloc( + this._getHomeUseCase, + ) : super(const HomeState()) { + on(_getHomeEvent); + } + + /// ------------UseCases------------ + final GetHomeUseCase _getHomeUseCase; + + /// ------------Variables------------ + + /// ------------Controllers------------ + + /// ------------Functions------------ + + /// ------------Api Calls------------ + FutureOr _getHomeEvent(event, emit) async { + await _getHomeUseCase(event.homeParams).then( + (value) { + value.fold( + (data) { + emit(state.copyWith(getHomeStatus: BaseComplete(data))); + }, + (error) { + emit(state.copyWith(getHomeStatus: BaseError(error.errorMessage))); + }, + ); + }, + ); + } +} diff --git a/lib/features/home/presentation/bloc/home_event.dart b/lib/features/home/presentation/bloc/home_event.dart new file mode 100644 index 0000000..2dc9c2f --- /dev/null +++ b/lib/features/home/presentation/bloc/home_event.dart @@ -0,0 +1,5 @@ +sealed class HomeEvent { + const HomeEvent(); +} + +class GetHomeEvent extends HomeEvent {} diff --git a/lib/features/home/presentation/bloc/home_state.dart b/lib/features/home/presentation/bloc/home_state.dart new file mode 100644 index 0000000..97a1646 --- /dev/null +++ b/lib/features/home/presentation/bloc/home_state.dart @@ -0,0 +1,15 @@ +import 'package:hadi_hoda_flutter/core/status/base_status.dart'; + +class HomeState { + final BaseStatus getHomeStatus; + + const HomeState({this.getHomeStatus = const BaseInit()}); + + HomeState copyWith({ + BaseStatus? getHomeStatus, + }) { + return HomeState( + getHomeStatus: getHomeStatus ?? this.getHomeStatus, + ); + } +} diff --git a/lib/features/intro/presentation/ui/intro_page.dart b/lib/features/home/presentation/ui/home_page.dart similarity index 95% rename from lib/features/intro/presentation/ui/intro_page.dart rename to lib/features/home/presentation/ui/home_page.dart index bc2c0d5..7237d46 100644 --- a/lib/features/intro/presentation/ui/intro_page.dart +++ b/lib/features/home/presentation/ui/home_page.dart @@ -7,8 +7,8 @@ import 'package:hadi_hoda_flutter/core/utils/check_platform.dart'; import 'package:hadi_hoda_flutter/core/utils/my_image.dart'; import 'package:hadi_hoda_flutter/core/utils/screen_size.dart'; -class IntroPage extends StatelessWidget { - const IntroPage({super.key}); +class HomePage extends StatelessWidget { + const HomePage({super.key}); @override Widget build(BuildContext context) { @@ -18,7 +18,7 @@ class IntroPage extends StatelessWidget { body: DecoratedBox( decoration: BoxDecoration( image: DecorationImage( - image: AssetImage(MyAssets.backgroundIntro), + image: AssetImage(MyAssets.backgroundHome), fit: BoxFit.cover, ), ), diff --git a/lib/features/intro/data/datasource/intro_datasource.dart b/lib/features/intro/data/datasource/intro_datasource.dart deleted file mode 100644 index 996c916..0000000 --- a/lib/features/intro/data/datasource/intro_datasource.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:hadi_hoda_flutter/core/constants/my_api.dart'; -import 'package:hadi_hoda_flutter/core/network/http_request.dart'; -import 'package:hadi_hoda_flutter/core/params/intro_params.dart'; -import 'package:hadi_hoda_flutter/core/response/base_response.dart'; -import 'package:hadi_hoda_flutter/features/intro/data/model/intro_model.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/entity/intro_entity.dart'; - -abstract class IIntroDatasource { - Future getData({required IntroParams params}); -} - -class IntroDatasourceImpl implements IIntroDatasource { - final IHttpRequest httpRequest; - - const IntroDatasourceImpl(this.httpRequest); - - @override - Future getData({required IntroParams params}) async { - final response = await httpRequest.get( - path: MyApi.baseUrl, - ); - - return BaseResponse.getData( - response?['data'], - (json) => IntroModel.fromJson(json), - ); - } -} diff --git a/lib/features/intro/data/model/intro_model.dart b/lib/features/intro/data/model/intro_model.dart deleted file mode 100644 index 548de3d..0000000 --- a/lib/features/intro/data/model/intro_model.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:hadi_hoda_flutter/features/intro/domain/entity/intro_entity.dart'; - -class IntroModel extends IntroEntity { - const IntroModel({ - super.id, - }); - - factory IntroModel.fromJson(Map json) { - return IntroModel( - id: json['id'], - ); - } -} diff --git a/lib/features/intro/data/repository_impl/intro_repository_impl.dart b/lib/features/intro/data/repository_impl/intro_repository_impl.dart deleted file mode 100644 index 362779c..0000000 --- a/lib/features/intro/data/repository_impl/intro_repository_impl.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:hadi_hoda_flutter/core/params/intro_params.dart'; -import 'package:flutter/foundation.dart'; -import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart'; -import 'package:hadi_hoda_flutter/core/utils/data_state.dart'; -import 'package:hadi_hoda_flutter/features/intro/data/datasource/intro_datasource.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/entity/intro_entity.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/repository/intro_repository.dart'; - -class IntroRepositoryImpl implements IIntroRepository { - final IIntroDatasource datasource; - - const IntroRepositoryImpl(this.datasource); - - @override - Future> getData({required IntroParams params}) async { - try { - final IntroEntity response = await datasource.getData(params: params); - return DataState.success(response); - } on MyException catch (e) { - return DataState.error(e); - } catch (e) { - if (kDebugMode) { - rethrow; - } else { - return DataState.error(MyException(errorMessage: '$e')); - } - } - } -} diff --git a/lib/features/intro/domain/repository/intro_repository.dart b/lib/features/intro/domain/repository/intro_repository.dart deleted file mode 100644 index a4b8814..0000000 --- a/lib/features/intro/domain/repository/intro_repository.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart'; -import 'package:hadi_hoda_flutter/core/params/intro_params.dart'; -import 'package:hadi_hoda_flutter/core/utils/data_state.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/entity/intro_entity.dart'; - -abstract class IIntroRepository { - Future> getData({required IntroParams params}); -} diff --git a/lib/features/intro/domain/usecases/get_intro_usecase.dart b/lib/features/intro/domain/usecases/get_intro_usecase.dart deleted file mode 100644 index 39c8bcc..0000000 --- a/lib/features/intro/domain/usecases/get_intro_usecase.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart'; -import 'package:hadi_hoda_flutter/core/params/intro_params.dart'; -import 'package:hadi_hoda_flutter/core/usecase/usecase.dart'; -import 'package:hadi_hoda_flutter/core/utils/data_state.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/entity/intro_entity.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/repository/intro_repository.dart'; - -class GetIntroUseCase implements UseCase { - final IIntroRepository repository; - - const GetIntroUseCase(this.repository); - - @override - Future> call(IntroParams params) { - return repository.getData(params: params); - } -} diff --git a/lib/features/intro/presentation/bloc/intro_bloc.dart b/lib/features/intro/presentation/bloc/intro_bloc.dart deleted file mode 100644 index bef4f8c..0000000 --- a/lib/features/intro/presentation/bloc/intro_bloc.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'dart:async'; -import 'package:bloc/bloc.dart'; -import 'package:hadi_hoda_flutter/core/status/base_status.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/entity/intro_entity.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/usecases/get_intro_usecase.dart'; -import 'package:hadi_hoda_flutter/features/intro/presentation/bloc/intro_event.dart'; -import 'package:hadi_hoda_flutter/features/intro/presentation/bloc/intro_state.dart'; - -class IntroBloc extends Bloc { - /// ------------constructor------------ - IntroBloc( - this._getIntroUseCase, - ) : super(const IntroState()) { - on(_getIntroEvent); - } - - /// ------------UseCases------------ - final GetIntroUseCase _getIntroUseCase; - - /// ------------Variables------------ - - /// ------------Controllers------------ - - /// ------------Functions------------ - - /// ------------Api Calls------------ - FutureOr _getIntroEvent(event, emit) async { - await _getIntroUseCase(event.introParams).then( - (value) { - value.fold( - (data) { - emit(state.copyWith(getIntroStatus: BaseComplete(data))); - }, - (error) { - emit(state.copyWith(getIntroStatus: BaseError(error.errorMessage))); - }, - ); - }, - ); - } -} diff --git a/lib/features/intro/presentation/bloc/intro_event.dart b/lib/features/intro/presentation/bloc/intro_event.dart deleted file mode 100644 index 4bdd16b..0000000 --- a/lib/features/intro/presentation/bloc/intro_event.dart +++ /dev/null @@ -1,5 +0,0 @@ -sealed class IntroEvent { - const IntroEvent(); -} - -class GetIntroEvent extends IntroEvent {} diff --git a/lib/features/intro/presentation/bloc/intro_state.dart b/lib/features/intro/presentation/bloc/intro_state.dart deleted file mode 100644 index 2c7fd3f..0000000 --- a/lib/features/intro/presentation/bloc/intro_state.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:hadi_hoda_flutter/core/status/base_status.dart'; - -class IntroState { - final BaseStatus getIntroStatus; - - const IntroState({this.getIntroStatus = const BaseInit()}); - - IntroState copyWith({ - BaseStatus? getIntroStatus, - }) { - return IntroState( - getIntroStatus: getIntroStatus ?? this.getIntroStatus, - ); - } -} diff --git a/lib/init_bindings.dart b/lib/init_bindings.dart index 215ccac..d06ad50 100644 --- a/lib/init_bindings.dart +++ b/lib/init_bindings.dart @@ -3,10 +3,10 @@ import 'dart:io'; import 'package:hadi_hoda_flutter/core/constants/my_constants.dart'; import 'package:hadi_hoda_flutter/core/network/http_request.dart'; import 'package:hadi_hoda_flutter/core/network/http_request_impl.dart'; -import 'package:hadi_hoda_flutter/features/intro/data/datasource/intro_datasource.dart'; -import 'package:hadi_hoda_flutter/features/intro/data/repository_impl/intro_repository_impl.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/repository/intro_repository.dart'; -import 'package:hadi_hoda_flutter/features/intro/domain/usecases/get_intro_usecase.dart'; +import 'package:hadi_hoda_flutter/features/home/data/datasource/home_datasource.dart'; +import 'package:hadi_hoda_flutter/features/home/data/repository_impl/home_repository_impl.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/repository/home_repository.dart'; +import 'package:hadi_hoda_flutter/features/home/domain/usecases/get_home_usecase.dart'; import 'package:hadi_hoda_flutter/features/level/data/datasource/level_datasource.dart'; import 'package:hadi_hoda_flutter/features/level/data/repository_impl/level_repository_impl.dart'; import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart'; @@ -38,10 +38,10 @@ void initBindings() { locator.registerLazySingleton(() => SampleRepositoryImpl(locator())); locator.registerLazySingleton(() => GetSampleUseCase(locator())); - /// Intro Feature - locator.registerLazySingleton(() => IntroDatasourceImpl(locator())); - locator.registerLazySingleton(() => IntroRepositoryImpl(locator())); - locator.registerLazySingleton(() => GetIntroUseCase(locator())); + /// Home Feature + locator.registerLazySingleton(() => HomeDatasourceImpl(locator())); + locator.registerLazySingleton(() => HomeRepositoryImpl(locator())); + locator.registerLazySingleton(() => GetHomeUseCase(locator())); /// Question Feature locator.registerLazySingleton(() => QuestionDatasourceImpl(locator()));