Browse Source

change: intro -> home

pull/9/head
AmirrezaChegini 1 week ago
parent
commit
5adb99f7e0
  1. 2
      lib/common_ui/resources/my_assets.dart
  2. 2
      lib/core/middleware/auth_middleware.dart
  3. 13
      lib/core/params/home_params.dart
  4. 13
      lib/core/params/intro_params.dart
  5. 16
      lib/core/routers/my_routes.dart
  6. 2
      lib/core/widgets/answer_box/styles/picture_box.dart
  7. 28
      lib/features/home/data/datasource/home_datasource.dart
  8. 13
      lib/features/home/data/model/home_model.dart
  9. 29
      lib/features/home/data/repository_impl/home_repository_impl.dart
  10. 4
      lib/features/home/domain/entity/home_entity.dart
  11. 8
      lib/features/home/domain/repository/home_repository.dart
  12. 17
      lib/features/home/domain/usecases/get_home_usecase.dart
  13. 41
      lib/features/home/presentation/bloc/home_bloc.dart
  14. 5
      lib/features/home/presentation/bloc/home_event.dart
  15. 15
      lib/features/home/presentation/bloc/home_state.dart
  16. 6
      lib/features/home/presentation/ui/home_page.dart
  17. 28
      lib/features/intro/data/datasource/intro_datasource.dart
  18. 13
      lib/features/intro/data/model/intro_model.dart
  19. 29
      lib/features/intro/data/repository_impl/intro_repository_impl.dart
  20. 8
      lib/features/intro/domain/repository/intro_repository.dart
  21. 17
      lib/features/intro/domain/usecases/get_intro_usecase.dart
  22. 41
      lib/features/intro/presentation/bloc/intro_bloc.dart
  23. 5
      lib/features/intro/presentation/bloc/intro_event.dart
  24. 15
      lib/features/intro/presentation/bloc/intro_state.dart
  25. 16
      lib/init_bindings.dart

2
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';

2
lib/core/middleware/auth_middleware.dart

@ -12,7 +12,7 @@ class AuthMiddleware {
static FutureOr<String?> redirect(BuildContext context, GoRouterState state) async {
if (AuthStorage.isLogin()) {
return Routes.introPage;
return Routes.homePage;
} else {
return null;
}

13
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,
);
}
}

13
lib/core/params/intro_params.dart

@ -1,13 +0,0 @@
class IntroParams {
int? id;
IntroParams({this.id});
IntroParams copyWith({
int? id,
}) {
return IntroParams(
id: id ?? this.id,
);
}
}

16
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(

2
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,
),

28
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<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),
);
}
}

13
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<String, dynamic> json) {
return HomeModel(
id: json['id'],
);
}
}

29
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<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'));
}
}
}
}

4
lib/features/intro/domain/entity/intro_entity.dart → 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,
});

8
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<DataState<HomeEntity, MyException>> getData({required HomeParams params});
}

17
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<HomeEntity, HomeParams> {
final IHomeRepository repository;
const GetHomeUseCase(this.repository);
@override
Future<DataState<HomeEntity, MyException>> call(HomeParams params) {
return repository.getData(params: params);
}
}

41
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<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)));
},
);
},
);
}
}

5
lib/features/home/presentation/bloc/home_event.dart

@ -0,0 +1,5 @@
sealed class HomeEvent {
const HomeEvent();
}
class GetHomeEvent extends HomeEvent {}

15
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,
);
}
}

6
lib/features/intro/presentation/ui/intro_page.dart → 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,
),
),

28
lib/features/intro/data/datasource/intro_datasource.dart

@ -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),
);
}
}

13
lib/features/intro/data/model/intro_model.dart

@ -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'],
);
}
}

29
lib/features/intro/data/repository_impl/intro_repository_impl.dart

@ -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'));
}
}
}
}

8
lib/features/intro/domain/repository/intro_repository.dart

@ -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});
}

17
lib/features/intro/domain/usecases/get_intro_usecase.dart

@ -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);
}
}

41
lib/features/intro/presentation/bloc/intro_bloc.dart

@ -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)));
},
);
},
);
}
}

5
lib/features/intro/presentation/bloc/intro_event.dart

@ -1,5 +0,0 @@
sealed class IntroEvent {
const IntroEvent();
}
class GetIntroEvent extends IntroEvent {}

15
lib/features/intro/presentation/bloc/intro_state.dart

@ -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,
);
}
}

16
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<ISampleRepository>(() => SampleRepositoryImpl(locator()));
locator.registerLazySingleton<GetSampleUseCase>(() => GetSampleUseCase(locator()));
/// Intro Feature
locator.registerLazySingleton<IIntroDatasource>(() => IntroDatasourceImpl(locator()));
locator.registerLazySingleton<IIntroRepository>(() => IntroRepositoryImpl(locator()));
locator.registerLazySingleton<GetIntroUseCase>(() => GetIntroUseCase(locator()));
/// Home Feature
locator.registerLazySingleton<IHomeDatasource>(() => HomeDatasourceImpl(locator()));
locator.registerLazySingleton<IHomeRepository>(() => HomeRepositoryImpl(locator()));
locator.registerLazySingleton<GetHomeUseCase>(() => GetHomeUseCase(locator()));
/// Question Feature
locator.registerLazySingleton<IQuestionDatasource>(() => QuestionDatasourceImpl(locator()));

Loading…
Cancel
Save