|
|
|
@ -0,0 +1,54 @@ |
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
import 'package:shia_game_flutter/core/params/awards_params.dart'; |
|
|
|
import 'package:shia_game_flutter/core/status/base_status.dart'; |
|
|
|
import 'package:shia_game_flutter/features/awards/domain/entity/awards_entity.dart'; |
|
|
|
import 'package:shia_game_flutter/features/awards/domain/usecases/get_awards_usecase.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
|
|
|
|
class AwardsController extends GetxController with StateMixin { |
|
|
|
/// ----- Constructor ----- |
|
|
|
AwardsController(this.getAwardsUseCase); |
|
|
|
|
|
|
|
@override |
|
|
|
void onInit() { |
|
|
|
super.onInit(); |
|
|
|
change('', status: RxStatus.success()); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
void onClose() { |
|
|
|
textEditingController.dispose(); |
|
|
|
super.onClose(); |
|
|
|
} |
|
|
|
|
|
|
|
/// ----- UseCases ----- |
|
|
|
final GetAwardsUseCase getAwardsUseCase; |
|
|
|
|
|
|
|
/// ----- Variables ----- |
|
|
|
final Rx<AwardsParams> awardsParams = Rx(AwardsParams()); |
|
|
|
final Rx<AwardsEntity> awardsEntity = Rx(const AwardsEntity()); |
|
|
|
|
|
|
|
/// ------ Controllers ------ |
|
|
|
final TextEditingController textEditingController = TextEditingController(); |
|
|
|
|
|
|
|
/// ------ Statuses ------ |
|
|
|
final Rx<BaseStatus> getAwardsStatus = Rx(const BaseInit()); |
|
|
|
|
|
|
|
/// ------ Functions ------ |
|
|
|
|
|
|
|
/// ------ Api Calls ------ |
|
|
|
Future<void> getAwards() async { |
|
|
|
change('', status: RxStatus.loading()); |
|
|
|
await getAwardsUseCase(awardsParams.value).then( |
|
|
|
(value) => value.fold( |
|
|
|
(data) { |
|
|
|
awardsEntity.value = data; |
|
|
|
change('', status: RxStatus.success()); |
|
|
|
}, |
|
|
|
(error) { |
|
|
|
change('', status: RxStatus.error(error.errorMessage)); |
|
|
|
}, |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
} |