import 'package:flutter/material.dart'; import 'package:rasadyar_core/core.dart'; import 'package:rasadyar_livestock/presentation/page/root/logic.dart'; class ProfileLogic extends GetxController { RootLogic rootLogic = Get.find(); RxInt selectedInformationType = 0.obs; Rxn birthDate = Rxn(); TextEditingController nameController = TextEditingController(); TextEditingController lastNameController = TextEditingController(); TextEditingController nationalCodeController = TextEditingController(); TextEditingController nationalIdController = TextEditingController(); TextEditingController birthdayController = TextEditingController(); TextEditingController oldPasswordController = TextEditingController(); TextEditingController newPasswordController = TextEditingController(); TextEditingController retryNewPasswordController = TextEditingController(); /* RxList cites = [].obs; Rxn selectedProvince = Rxn(); Rxn selectedCity = Rxn(); */ GlobalKey formKey = GlobalKey(); ImagePicker imagePicker = ImagePicker(); Rxn selectedImage = Rxn(); final RxnString _base64Image = RxnString(); RxBool isOnLoading = false.obs; @override void onInit() { super.onInit(); ever(selectedImage, (data) async { if (data?.path != null) { _base64Image.value = await convertImageToBase64(data!.path); } }); } @override void onReady() { super.onReady(); getUserProfile(); /*selectedProvince.listen((p0) => getCites()); userProfile.listen((data) { nameController.text = data.data?.firstName ?? ''; lastNameController.text = data.data?.lastName ?? ''; nationalCodeController.text = data.data?.nationalCode ?? ''; nationalIdController.text = data.data?.nationalId ?? ''; birthdayController.text = data.data?.birthday?.toJalali.formatCompactDate() ?? ''; birthDate.value = data.data?.birthday?.toJalali; selectedProvince.value = IranProvinceCityModel( name: data.data?.province ?? '', id: data.data?.provinceNumber ?? 0, ); selectedCity.value = IranProvinceCityModel( name: data.data?.city ?? '', id: data.data?.cityNumber ?? 0, ); });*/ } Future getUserProfile() async { /*userProfile.value = Resource.loading(); await safeCall( call: () async => await rootLogic.chickenRepository.getUserProfile( token: rootLogic.tokenService.accessToken.value!, ), onSuccess: (result) { if (result != null) { userProfile.value = Resource.success(result); } }, onError: (error, stackTrace) {}, );*/ } Future getCites() async { /*await safeCall( call: () => rootLogic.chickenRepository.getCity(provinceName: selectedProvince.value?.name ?? ''), onSuccess: (result) { if (result != null && result.isNotEmpty) { cites.value = result; } }, );*/ } Future updateUserProfile() async { /* UserProfile userProfile = UserProfile( firstName: nameController.text, lastName: lastNameController.text, nationalCode: nationalCodeController.text, nationalId: nationalIdController.text, birthday: birthDate.value?.toDateTime().formattedDashedGregorian.toString(), image: _base64Image.value, personType: 'self', type: 'self_profile', ); isOnLoading.value = true; await safeCall( call: () async => await rootLogic.chickenRepository.updateUserProfile( token: rootLogic.tokenService.accessToken.value!, userProfile: userProfile, ), onSuccess: (result) { isOnLoading.value = false; }, onError: (error, stackTrace) { isOnLoading.value = false; }, );*/ } Future updatePassword() async { /* if (formKey.currentState?.validate() ?? false) { ChangePasswordRequestModel model = ChangePasswordRequestModel( username: userProfile.value.data?.mobile, password: newPasswordController.text, ); await safeCall( call: () async => await rootLogic.chickenRepository.updatePassword( token: rootLogic.tokenService.accessToken.value!, model: model, ), ); }*/ } void clearPasswordForm() { oldPasswordController.clear(); newPasswordController.clear(); retryNewPasswordController.clear(); } }