|
|
|
@ -0,0 +1,54 @@ |
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
import 'package:shia_game_flutter/core/params/shop_params.dart'; |
|
|
|
import 'package:shia_game_flutter/core/status/base_status.dart'; |
|
|
|
import 'package:shia_game_flutter/features/shop/domain/entity/shop_entity.dart'; |
|
|
|
import 'package:shia_game_flutter/features/shop/domain/usecases/get_shop_usecase.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
|
|
|
|
class ShopController extends GetxController with StateMixin { |
|
|
|
/// ----- Constructor ----- |
|
|
|
ShopController(this.getShopUseCase); |
|
|
|
|
|
|
|
@override |
|
|
|
void onInit() { |
|
|
|
super.onInit(); |
|
|
|
change('', status: RxStatus.success()); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
void onClose() { |
|
|
|
textEditingController.dispose(); |
|
|
|
super.onClose(); |
|
|
|
} |
|
|
|
|
|
|
|
/// ----- UseCases ----- |
|
|
|
final GetShopUseCase getShopUseCase; |
|
|
|
|
|
|
|
/// ----- Variables ----- |
|
|
|
final Rx<ShopParams> shopParams = Rx(ShopParams()); |
|
|
|
final Rx<ShopEntity> shopEntity = Rx(const ShopEntity()); |
|
|
|
|
|
|
|
/// ------ Controllers ------ |
|
|
|
final TextEditingController textEditingController = TextEditingController(); |
|
|
|
|
|
|
|
/// ------ Statuses ------ |
|
|
|
final Rx<BaseStatus> getShopStatus = Rx(const BaseInit()); |
|
|
|
|
|
|
|
/// ------ Functions ------ |
|
|
|
|
|
|
|
/// ------ Api Calls ------ |
|
|
|
Future<void> getShop() async { |
|
|
|
change('', status: RxStatus.loading()); |
|
|
|
await getShopUseCase(shopParams.value).then( |
|
|
|
(value) => value.fold( |
|
|
|
(data) { |
|
|
|
shopEntity.value = data; |
|
|
|
change('', status: RxStatus.success()); |
|
|
|
}, |
|
|
|
(error) { |
|
|
|
change('', status: RxStatus.error(error.errorMessage)); |
|
|
|
}, |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
} |