23 changed files with 306 additions and 65 deletions
-
13lib/core/params/master_params.dart
-
4lib/core/routers/my_routes.dart
-
4lib/core/widgets/app_bar/master_app_bar.dart
-
4lib/core/widgets/bottom_nav_bar/bottom_nav_bar.dart
-
2lib/core/widgets/bottom_nav_bar/styles/bottom_nav_bar_item.dart
-
2lib/core/widgets/bottom_nav_bar/styles/bottom_nav_bar_profile_item.dart
-
2lib/features/awards/presentation/binding/awards_binding.dart
-
2lib/features/home/presentation/binding/home_binding.dart
-
27lib/features/home/presentation/controller/home_controller.dart
-
36lib/features/home/presentation/pages/home_page.dart
-
28lib/features/master/data/datasource/master_datasource.dart
-
13lib/features/master/data/model/master_model.dart
-
29lib/features/master/data/repository_impl/master_repository_impl.dart
-
5lib/features/master/domain/entity/bottom_nav_entity.dart
-
14lib/features/master/domain/entity/master_entity.dart
-
8lib/features/master/domain/repository/master_repository.dart
-
20lib/features/master/presentation/binding/master_binding.dart
-
85lib/features/master/presentation/controller/master_controller.dart
-
25lib/features/master/presentation/ui/master_page.dart
-
2lib/features/profile/presentation/binding/profile_binding.dart
-
2lib/features/shop/presentation/binding/shop_binding.dart
-
42lib/init_bindings.dart
-
2lib/main.dart
@ -0,0 +1,13 @@ |
|||||
|
class MasterParams { |
||||
|
int? id; |
||||
|
|
||||
|
MasterParams({this.id}); |
||||
|
|
||||
|
MasterParams copyWith({ |
||||
|
int? id, |
||||
|
}) { |
||||
|
return MasterParams( |
||||
|
id: id ?? this.id, |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
import 'package:shia_game_flutter/core/constants/my_api.dart'; |
||||
|
import 'package:shia_game_flutter/core/network/http_request.dart'; |
||||
|
import 'package:shia_game_flutter/core/params/master_params.dart'; |
||||
|
import 'package:shia_game_flutter/core/response/base_response.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/data/model/master_model.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/domain/entity/master_entity.dart'; |
||||
|
|
||||
|
abstract class IMasterDatasource { |
||||
|
Future<MasterEntity> getData({required MasterParams params}); |
||||
|
} |
||||
|
|
||||
|
class MasterDatasourceImpl implements IMasterDatasource { |
||||
|
final IHttpRequest httpRequest; |
||||
|
|
||||
|
const MasterDatasourceImpl(this.httpRequest); |
||||
|
|
||||
|
@override |
||||
|
Future<MasterEntity> getData({required MasterParams params}) async { |
||||
|
final response = await httpRequest.get( |
||||
|
path: MyApi.baseUrl, |
||||
|
); |
||||
|
|
||||
|
return BaseResponse.getData<MasterEntity>( |
||||
|
response?['data'], |
||||
|
(json) => MasterModel.fromJson(json), |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
import 'package:shia_game_flutter/features/master/domain/entity/master_entity.dart'; |
||||
|
|
||||
|
class MasterModel extends MasterEntity { |
||||
|
const MasterModel({ |
||||
|
super.id, |
||||
|
}); |
||||
|
|
||||
|
factory MasterModel.fromJson(Map<String, dynamic> json) { |
||||
|
return MasterModel( |
||||
|
id: json['id'], |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
import 'package:flutter/foundation.dart'; |
||||
|
import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; |
||||
|
import 'package:shia_game_flutter/core/params/master_params.dart'; |
||||
|
import 'package:shia_game_flutter/core/utils/data_state.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/data/datasource/master_datasource.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/domain/entity/master_entity.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/domain/repository/master_repository.dart'; |
||||
|
|
||||
|
class MasterRepositoryImpl implements IMasterRepository { |
||||
|
final IMasterDatasource datasource; |
||||
|
|
||||
|
const MasterRepositoryImpl(this.datasource); |
||||
|
|
||||
|
@override |
||||
|
Future<DataState<MasterEntity, MyException>> getData({required MasterParams params}) async { |
||||
|
try { |
||||
|
final MasterEntity 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')); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
import 'package:equatable/equatable.dart'; |
||||
|
|
||||
|
class MasterEntity extends Equatable { |
||||
|
final int? id; |
||||
|
|
||||
|
const MasterEntity({ |
||||
|
this.id, |
||||
|
}); |
||||
|
|
||||
|
@override |
||||
|
List<Object?> get props => [ |
||||
|
id, |
||||
|
]; |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; |
||||
|
import 'package:shia_game_flutter/core/params/master_params.dart'; |
||||
|
import 'package:shia_game_flutter/core/utils/data_state.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/domain/entity/master_entity.dart'; |
||||
|
|
||||
|
abstract class IMasterRepository { |
||||
|
Future<DataState<MasterEntity, MyException>> getData({required MasterParams params}); |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
import 'package:shia_game_flutter/features/master/presentation/controller/master_controller.dart'; |
||||
|
import 'package:get/get.dart'; |
||||
|
|
||||
|
class MasterBinding extends Bindings { |
||||
|
@override |
||||
|
void dependencies() { |
||||
|
Get.put<MasterController>(MasterController(Get.find())); |
||||
|
} |
||||
|
|
||||
|
Future<void> deleteBindings() async { |
||||
|
await Future.wait([ |
||||
|
Get.delete<MasterController>(), |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
Future<void> refreshBinding() async { |
||||
|
await deleteBindings(); |
||||
|
dependencies(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
import 'package:flutter/cupertino.dart'; |
||||
|
import 'package:shia_game_flutter/common_ui/resources/my_assets.dart'; |
||||
|
import 'package:shia_game_flutter/core/params/master_params.dart'; |
||||
|
import 'package:shia_game_flutter/core/routers/my_routes.dart'; |
||||
|
import 'package:shia_game_flutter/core/status/base_status.dart'; |
||||
|
import 'package:shia_game_flutter/core/utils/my_localization.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/domain/entity/bottom_nav_entity.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/domain/entity/master_entity.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/domain/usecases/get_master_usecase.dart'; |
||||
|
import 'package:get/get.dart'; |
||||
|
|
||||
|
class MasterController extends GetxController with StateMixin { |
||||
|
/// ----- Constructor ----- |
||||
|
MasterController(this.getMasterUseCase); |
||||
|
|
||||
|
@override |
||||
|
void onInit() { |
||||
|
super.onInit(); |
||||
|
change('', status: RxStatus.success()); |
||||
|
} |
||||
|
|
||||
|
@override |
||||
|
void onClose() { |
||||
|
textEditingController.dispose(); |
||||
|
super.onClose(); |
||||
|
} |
||||
|
|
||||
|
/// ----- UseCases ----- |
||||
|
final GetMasterUseCase getMasterUseCase; |
||||
|
|
||||
|
/// ----- Variables ----- |
||||
|
final Rx<MasterParams> masterParams = Rx(MasterParams()); |
||||
|
final Rx<MasterEntity> masterEntity = Rx(const MasterEntity()); |
||||
|
final List<BottomNavEntity> bottomNavList = [ |
||||
|
BottomNavEntity( |
||||
|
icon: MyAssets.iconHome, |
||||
|
title: Get.context?.translate.home, |
||||
|
route: Routes.homePage, |
||||
|
), |
||||
|
BottomNavEntity( |
||||
|
icon: MyAssets.iconShop, |
||||
|
title: Get.context?.translate.shop, |
||||
|
route: Routes.shopPage, |
||||
|
), |
||||
|
BottomNavEntity( |
||||
|
icon: MyAssets.iconAwards, |
||||
|
title: Get.context?.translate.awards, |
||||
|
route: Routes.awardsPage, |
||||
|
), |
||||
|
BottomNavEntity( |
||||
|
icon: MyAssets.iconProfile, |
||||
|
title: Get.context?.translate.profile, |
||||
|
route: Routes.profilePage, |
||||
|
), |
||||
|
]; |
||||
|
final Rx<int> selectedIndex = Rx(0); |
||||
|
|
||||
|
/// ------ Controllers ------ |
||||
|
final TextEditingController textEditingController = TextEditingController(); |
||||
|
|
||||
|
/// ------ Statuses ------ |
||||
|
final Rx<BaseStatus> getMasterStatus = Rx(const BaseInit()); |
||||
|
|
||||
|
/// ------ Functions ------ |
||||
|
void onChangeBottomNavBar(int index) { |
||||
|
selectedIndex.value = index; |
||||
|
Get.rootDelegate.toNamed(bottomNavList[index].route ?? ''); |
||||
|
} |
||||
|
|
||||
|
/// ------ Api Calls ------ |
||||
|
Future<void> getMaster() async { |
||||
|
change('', status: RxStatus.loading()); |
||||
|
await getMasterUseCase(masterParams.value).then( |
||||
|
(value) => value.fold( |
||||
|
(data) { |
||||
|
masterEntity.value = data; |
||||
|
change('', status: RxStatus.success()); |
||||
|
}, |
||||
|
(error) { |
||||
|
change('', status: RxStatus.error(error.errorMessage)); |
||||
|
}, |
||||
|
), |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
import 'package:flutter/material.dart'; |
||||
|
import 'package:shia_game_flutter/common_ui/theme/my_theme.dart'; |
||||
|
import 'package:shia_game_flutter/core/routers/my_routes.dart'; |
||||
|
import 'package:shia_game_flutter/core/widgets/app_bar/master_app_bar.dart'; |
||||
|
import 'package:shia_game_flutter/core/widgets/bottom_nav_bar/bottom_nav_bar.dart'; |
||||
|
import 'package:shia_game_flutter/features/master/presentation/controller/master_controller.dart'; |
||||
|
import 'package:get/get.dart'; |
||||
|
|
||||
|
class MasterPage extends GetView<MasterController> { |
||||
|
const MasterPage({super.key}); |
||||
|
|
||||
|
@override |
||||
|
Widget build(BuildContext context) { |
||||
|
return Scaffold( |
||||
|
backgroundColor: context.backgroundColor, |
||||
|
appBar: MasterAppBar(), |
||||
|
bottomNavigationBar: BottomNavBar(), |
||||
|
body: GetRouterOutlet( |
||||
|
initialRoute: Routes.homePage, |
||||
|
anchorRoute: Routes.masterPage, |
||||
|
delegate: Get.rootDelegate, |
||||
|
), |
||||
|
); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue