25 changed files with 193 additions and 193 deletions
-
2lib/common_ui/resources/my_assets.dart
-
2lib/core/middleware/auth_middleware.dart
-
13lib/core/params/home_params.dart
-
13lib/core/params/intro_params.dart
-
16lib/core/routers/my_routes.dart
-
2lib/core/widgets/answer_box/styles/picture_box.dart
-
28lib/features/home/data/datasource/home_datasource.dart
-
13lib/features/home/data/model/home_model.dart
-
29lib/features/home/data/repository_impl/home_repository_impl.dart
-
4lib/features/home/domain/entity/home_entity.dart
-
8lib/features/home/domain/repository/home_repository.dart
-
17lib/features/home/domain/usecases/get_home_usecase.dart
-
41lib/features/home/presentation/bloc/home_bloc.dart
-
5lib/features/home/presentation/bloc/home_event.dart
-
15lib/features/home/presentation/bloc/home_state.dart
-
6lib/features/home/presentation/ui/home_page.dart
-
28lib/features/intro/data/datasource/intro_datasource.dart
-
13lib/features/intro/data/model/intro_model.dart
-
29lib/features/intro/data/repository_impl/intro_repository_impl.dart
-
8lib/features/intro/domain/repository/intro_repository.dart
-
17lib/features/intro/domain/usecases/get_intro_usecase.dart
-
41lib/features/intro/presentation/bloc/intro_bloc.dart
-
5lib/features/intro/presentation/bloc/intro_event.dart
-
15lib/features/intro/presentation/bloc/intro_state.dart
-
16lib/init_bindings.dart
@ -0,0 +1,13 @@ |
|||
class HomeParams { |
|||
int? id; |
|||
|
|||
HomeParams({this.id}); |
|||
|
|||
HomeParams copyWith({ |
|||
int? id, |
|||
}) { |
|||
return HomeParams( |
|||
id: id ?? this.id, |
|||
); |
|||
} |
|||
} |
@ -1,13 +0,0 @@ |
|||
class IntroParams { |
|||
int? id; |
|||
|
|||
IntroParams({this.id}); |
|||
|
|||
IntroParams copyWith({ |
|||
int? id, |
|||
}) { |
|||
return IntroParams( |
|||
id: id ?? this.id, |
|||
); |
|||
} |
|||
} |
@ -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<HomeEntity> getData({required HomeParams params}); |
|||
} |
|||
|
|||
class HomeDatasourceImpl implements IHomeDatasource { |
|||
final IHttpRequest httpRequest; |
|||
|
|||
const HomeDatasourceImpl(this.httpRequest); |
|||
|
|||
@override |
|||
Future<HomeEntity> getData({required HomeParams params}) async { |
|||
final response = await httpRequest.get( |
|||
path: MyApi.baseUrl, |
|||
); |
|||
|
|||
return BaseResponse.getData<HomeEntity>( |
|||
response?['data'], |
|||
(json) => HomeModel.fromJson(json), |
|||
); |
|||
} |
|||
} |
@ -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<String, dynamic> json) { |
|||
return HomeModel( |
|||
id: json['id'], |
|||
); |
|||
} |
|||
} |
@ -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<DataState<HomeEntity, MyException>> 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')); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -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, |
|||
}); |
|||
|
@ -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<DataState<HomeEntity, MyException>> getData({required HomeParams params}); |
|||
} |
@ -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<HomeEntity, HomeParams> { |
|||
final IHomeRepository repository; |
|||
|
|||
const GetHomeUseCase(this.repository); |
|||
|
|||
@override |
|||
Future<DataState<HomeEntity, MyException>> call(HomeParams params) { |
|||
return repository.getData(params: params); |
|||
} |
|||
} |
@ -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<HomeEvent, HomeState> { |
|||
/// ------------constructor------------ |
|||
HomeBloc( |
|||
this._getHomeUseCase, |
|||
) : super(const HomeState()) { |
|||
on<GetHomeEvent>(_getHomeEvent); |
|||
} |
|||
|
|||
/// ------------UseCases------------ |
|||
final GetHomeUseCase _getHomeUseCase; |
|||
|
|||
/// ------------Variables------------ |
|||
|
|||
/// ------------Controllers------------ |
|||
|
|||
/// ------------Functions------------ |
|||
|
|||
/// ------------Api Calls------------ |
|||
FutureOr<void> _getHomeEvent(event, emit) async { |
|||
await _getHomeUseCase(event.homeParams).then( |
|||
(value) { |
|||
value.fold( |
|||
(data) { |
|||
emit(state.copyWith(getHomeStatus: BaseComplete<HomeEntity>(data))); |
|||
}, |
|||
(error) { |
|||
emit(state.copyWith(getHomeStatus: BaseError(error.errorMessage))); |
|||
}, |
|||
); |
|||
}, |
|||
); |
|||
} |
|||
} |
@ -0,0 +1,5 @@ |
|||
sealed class HomeEvent { |
|||
const HomeEvent(); |
|||
} |
|||
|
|||
class GetHomeEvent extends HomeEvent {} |
@ -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, |
|||
); |
|||
} |
|||
} |
@ -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<IntroEntity> getData({required IntroParams params}); |
|||
} |
|||
|
|||
class IntroDatasourceImpl implements IIntroDatasource { |
|||
final IHttpRequest httpRequest; |
|||
|
|||
const IntroDatasourceImpl(this.httpRequest); |
|||
|
|||
@override |
|||
Future<IntroEntity> getData({required IntroParams params}) async { |
|||
final response = await httpRequest.get( |
|||
path: MyApi.baseUrl, |
|||
); |
|||
|
|||
return BaseResponse.getData<IntroEntity>( |
|||
response?['data'], |
|||
(json) => IntroModel.fromJson(json), |
|||
); |
|||
} |
|||
} |
@ -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<String, dynamic> json) { |
|||
return IntroModel( |
|||
id: json['id'], |
|||
); |
|||
} |
|||
} |
@ -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<DataState<IntroEntity, MyException>> 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')); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -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<DataState<IntroEntity, MyException>> getData({required IntroParams params}); |
|||
} |
@ -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<IntroEntity, IntroParams> { |
|||
final IIntroRepository repository; |
|||
|
|||
const GetIntroUseCase(this.repository); |
|||
|
|||
@override |
|||
Future<DataState<IntroEntity, MyException>> call(IntroParams params) { |
|||
return repository.getData(params: params); |
|||
} |
|||
} |
@ -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<IntroEvent, IntroState> { |
|||
/// ------------constructor------------ |
|||
IntroBloc( |
|||
this._getIntroUseCase, |
|||
) : super(const IntroState()) { |
|||
on<GetIntroEvent>(_getIntroEvent); |
|||
} |
|||
|
|||
/// ------------UseCases------------ |
|||
final GetIntroUseCase _getIntroUseCase; |
|||
|
|||
/// ------------Variables------------ |
|||
|
|||
/// ------------Controllers------------ |
|||
|
|||
/// ------------Functions------------ |
|||
|
|||
/// ------------Api Calls------------ |
|||
FutureOr<void> _getIntroEvent(event, emit) async { |
|||
await _getIntroUseCase(event.introParams).then( |
|||
(value) { |
|||
value.fold( |
|||
(data) { |
|||
emit(state.copyWith(getIntroStatus: BaseComplete<IntroEntity>(data))); |
|||
}, |
|||
(error) { |
|||
emit(state.copyWith(getIntroStatus: BaseError(error.errorMessage))); |
|||
}, |
|||
); |
|||
}, |
|||
); |
|||
} |
|||
} |
@ -1,5 +0,0 @@ |
|||
sealed class IntroEvent { |
|||
const IntroEvent(); |
|||
} |
|||
|
|||
class GetIntroEvent extends IntroEvent {} |
@ -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, |
|||
); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue