|
|
|
@ -0,0 +1,54 @@ |
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
import 'package:shia_game_flutter/core/params/profile_params.dart'; |
|
|
|
import 'package:shia_game_flutter/core/status/base_status.dart'; |
|
|
|
import 'package:shia_game_flutter/features/profile/domain/entity/profile_entity.dart'; |
|
|
|
import 'package:shia_game_flutter/features/profile/domain/usecases/get_profile_usecase.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
|
|
|
|
class ProfileController extends GetxController with StateMixin { |
|
|
|
/// ----- Constructor ----- |
|
|
|
ProfileController(this.getProfileUseCase); |
|
|
|
|
|
|
|
@override |
|
|
|
void onInit() { |
|
|
|
super.onInit(); |
|
|
|
change('', status: RxStatus.success()); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
void onClose() { |
|
|
|
textEditingController.dispose(); |
|
|
|
super.onClose(); |
|
|
|
} |
|
|
|
|
|
|
|
/// ----- UseCases ----- |
|
|
|
final GetProfileUseCase getProfileUseCase; |
|
|
|
|
|
|
|
/// ----- Variables ----- |
|
|
|
final Rx<ProfileParams> profileParams = Rx(ProfileParams()); |
|
|
|
final Rx<ProfileEntity> profileEntity = Rx(const ProfileEntity()); |
|
|
|
|
|
|
|
/// ------ Controllers ------ |
|
|
|
final TextEditingController textEditingController = TextEditingController(); |
|
|
|
|
|
|
|
/// ------ Statuses ------ |
|
|
|
final Rx<BaseStatus> getProfileStatus = Rx(const BaseInit()); |
|
|
|
|
|
|
|
/// ------ Functions ------ |
|
|
|
|
|
|
|
/// ------ Api Calls ------ |
|
|
|
Future<void> getProfile() async { |
|
|
|
change('', status: RxStatus.loading()); |
|
|
|
await getProfileUseCase(profileParams.value).then( |
|
|
|
(value) => value.fold( |
|
|
|
(data) { |
|
|
|
profileEntity.value = data; |
|
|
|
change('', status: RxStatus.success()); |
|
|
|
}, |
|
|
|
(error) { |
|
|
|
change('', status: RxStatus.error(error.errorMessage)); |
|
|
|
}, |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
} |