|  |  |  | @ -1,12 +1,13 @@ | 
		
	
		
			
				|  |  |  |  | import 'dart:developer'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/material.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/app_export.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/app_state.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/cache_consts.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/enums.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/utils/loading_utils.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/utils/request_utils.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/utils/utils.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/utils/validation_utils.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/authentication_repo.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/models/request_models/check_patient_authentication_request_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/models/resp_models/check_activation_code_resp_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/models/resp_models/select_device_by_imei.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/presentation/authentication/login.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -16,31 +17,28 @@ import 'package:hmg_patient_app_new/services/error_handler_service.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/services/navigation_service.dart'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |   AuthenticationRepo authenticationRepo; | 
		
	
		
			
				|  |  |  |  |   AppState appState; | 
		
	
		
			
				|  |  |  |  |   ErrorHandlerService errorHandlerService; | 
		
	
		
			
				|  |  |  |  |   DialogService dialogService; | 
		
	
		
			
				|  |  |  |  |   NavigationService navigationService; | 
		
	
		
			
				|  |  |  |  |   CacheService cacheService; | 
		
	
		
			
				|  |  |  |  |   final AuthenticationRepo _authenticationRepo; | 
		
	
		
			
				|  |  |  |  |   final AppState _appState; | 
		
	
		
			
				|  |  |  |  |   final ErrorHandlerService _errorHandlerService; | 
		
	
		
			
				|  |  |  |  |   final DialogService _dialogService; | 
		
	
		
			
				|  |  |  |  |   final NavigationService _navigationService; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   AuthenticationViewModel({ | 
		
	
		
			
				|  |  |  |  |     required this.appState, | 
		
	
		
			
				|  |  |  |  |     required this.authenticationRepo, | 
		
	
		
			
				|  |  |  |  |     required this.errorHandlerService, | 
		
	
		
			
				|  |  |  |  |     required this.dialogService, | 
		
	
		
			
				|  |  |  |  |     required this.navigationService, | 
		
	
		
			
				|  |  |  |  |     required this.cacheService, | 
		
	
		
			
				|  |  |  |  |   }); | 
		
	
		
			
				|  |  |  |  |     required AppState appState, | 
		
	
		
			
				|  |  |  |  |     required AuthenticationRepo authenticationRepo, | 
		
	
		
			
				|  |  |  |  |     required ErrorHandlerService errorHandlerService, | 
		
	
		
			
				|  |  |  |  |     required DialogService dialogService, | 
		
	
		
			
				|  |  |  |  |     required NavigationService navigationService, | 
		
	
		
			
				|  |  |  |  |     required CacheService cacheService, | 
		
	
		
			
				|  |  |  |  |   })  : _navigationService = navigationService, | 
		
	
		
			
				|  |  |  |  |         _dialogService = dialogService, | 
		
	
		
			
				|  |  |  |  |         _errorHandlerService = errorHandlerService, | 
		
	
		
			
				|  |  |  |  |         _appState = appState, | 
		
	
		
			
				|  |  |  |  |         _authenticationRepo = authenticationRepo; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   final TextEditingController nationalIdController = TextEditingController(); | 
		
	
		
			
				|  |  |  |  |   final TextEditingController phoneNumberController = TextEditingController(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void login() { | 
		
	
		
			
				|  |  |  |  |     if (ValidationUtils.isValidatePhoneAndId(nationalId: nationalIdController.text, phoneNumber: phoneNumberController.text)) { | 
		
	
		
			
				|  |  |  |  |     } else {} | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   //checkUserAuthentication(); | 
		
	
		
			
				|  |  |  |  |   bool isDubai = false; | 
		
	
		
			
				|  |  |  |  |   bool authenticated = false; | 
		
	
		
			
				|  |  |  |  |   late int mobileNumber; | 
		
	
	
		
			
				
					|  |  |  | @ -61,106 +59,141 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |   late int isHijri; | 
		
	
		
			
				|  |  |  |  |   var healthId; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> onLoginPressed() async { | 
		
	
		
			
				|  |  |  |  |     try { | 
		
	
		
			
				|  |  |  |  |       LoadingUtils.showFullScreenLoading(); | 
		
	
		
			
				|  |  |  |  |       //TODO:  We will remove this delay | 
		
	
		
			
				|  |  |  |  |       await Future.delayed(Duration(seconds: 3)); | 
		
	
		
			
				|  |  |  |  |       var data = _appState.getSelectDeviceByImeiRespModelElement; | 
		
	
		
			
				|  |  |  |  |       log("Cached IMEI data: ${data?.toJson()}"); | 
		
	
		
			
				|  |  |  |  |       if (data != null) { | 
		
	
		
			
				|  |  |  |  |         await _handleExistingImeiData(data); | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         await _handleNewImeiRegistration(); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } catch (e) { | 
		
	
		
			
				|  |  |  |  |       log("Error in onLoginPressed: $e"); | 
		
	
		
			
				|  |  |  |  |       LoadingUtils.hideFullScreenLoader(); | 
		
	
		
			
				|  |  |  |  |       _dialogService.showErrorDialog(message: "An unexpected error occurred. Please try again.", onOkPressed: () {}); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> selectDeviceImei({required Function(dynamic data) onSuccess, Function(String)? onError}) async { | 
		
	
		
			
				|  |  |  |  |     String firebaseToken = appState.deviceToken == "" | 
		
	
		
			
				|  |  |  |  |     // LoadingUtils.showFullScreenLoading(); | 
		
	
		
			
				|  |  |  |  |     String firebaseToken = _appState.deviceToken == "" | 
		
	
		
			
				|  |  |  |  |         ? "dOGRRszQQMGe_9wA5Hx3kO:APA91bFV5IcIJXvcCXXk0tc2ddtZgWwCPq7sGSuPr-YW7iiJpQZKgFGN9GAzCVOWL8MfheaP1slE8MdxB7lczdPBGdONQ7WbMmhgHcsUCUktq-hsapGXXqc" | 
		
	
		
			
				|  |  |  |  |         : appState.deviceToken; | 
		
	
		
			
				|  |  |  |  |     final result = await authenticationRepo.selectDeviceByImei(firebaseToken: firebaseToken); | 
		
	
		
			
				|  |  |  |  |         : _appState.deviceToken; | 
		
	
		
			
				|  |  |  |  |     final result = await _authenticationRepo.selectDeviceByImei(firebaseToken: firebaseToken); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     result.fold( | 
		
	
		
			
				|  |  |  |  |       (failure) async => await errorHandlerService.handleError(failure: failure), | 
		
	
		
			
				|  |  |  |  |       (failure) async { | 
		
	
		
			
				|  |  |  |  |         // LoadingUtils.hideFullScreenLoader(); | 
		
	
		
			
				|  |  |  |  |         await _errorHandlerService.handleError(failure: failure); | 
		
	
		
			
				|  |  |  |  |       }, | 
		
	
		
			
				|  |  |  |  |       (apiResponse) { | 
		
	
		
			
				|  |  |  |  |         // LoadingUtils.hideFullScreenLoader(); | 
		
	
		
			
				|  |  |  |  |         log("apiResponse: ${apiResponse.data.toString()}"); | 
		
	
		
			
				|  |  |  |  |         log("messageStatus: ${apiResponse.messageStatus.toString()}"); | 
		
	
		
			
				|  |  |  |  |         if (apiResponse.messageStatus == 1) { | 
		
	
		
			
				|  |  |  |  |           onSuccess(apiResponse.data); | 
		
	
		
			
				|  |  |  |  |         } else if (apiResponse.messageStatus == 2) { | 
		
	
		
			
				|  |  |  |  |           dialogService.showErrorDialog(message: "Message Status = 2", onOkPressed: () {}); | 
		
	
		
			
				|  |  |  |  |           _dialogService.showErrorDialog(message: "Message Status = 2", onOkPressed: () {}); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       }, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> onLoginPressed() async { | 
		
	
		
			
				|  |  |  |  |     var data = await cacheService.getObject(key: CacheConst.imeiUserData); | 
		
	
		
			
				|  |  |  |  |     //TODO:  Why??? | 
		
	
		
			
				|  |  |  |  |     cacheService.remove(key: CacheConst.registerDataForLogin); | 
		
	
		
			
				|  |  |  |  |     if (data != null) { | 
		
	
		
			
				|  |  |  |  |       SelectDeviceByImeiRespModelElement savedData = SelectDeviceByImeiRespModelElement.fromJson(data); | 
		
	
		
			
				|  |  |  |  |       // TODO : SavedLogin Page is not there or renamed. | 
		
	
		
			
				|  |  |  |  |       // navigationService.pushPage(page: SavedLogin(savedData)); | 
		
	
		
			
				|  |  |  |  |       // Navigator.of(context).push( | 
		
	
		
			
				|  |  |  |  |       //   MaterialPageRoute( | 
		
	
		
			
				|  |  |  |  |       //     builder: (BuildContext context) => SavedLogin(savedData), | 
		
	
		
			
				|  |  |  |  |       //   ), | 
		
	
		
			
				|  |  |  |  |       // ); | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       // Todo: Show Loader Here | 
		
	
		
			
				|  |  |  |  |       // GifLoaderDialogUtils.showMyDialog(context); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       selectDeviceImei( | 
		
	
		
			
				|  |  |  |  |         onSuccess: (dynamic respData) async { | 
		
	
		
			
				|  |  |  |  |           var data = await cacheService.getObject(key: CacheConst.imeiUserData); | 
		
	
		
			
				|  |  |  |  |           if (respData != null) { | 
		
	
		
			
				|  |  |  |  |             cacheService.saveObject(key: CacheConst.imeiUserData, value: respData); | 
		
	
		
			
				|  |  |  |  |   Future<void> _handleExistingImeiData(dynamic data) async { | 
		
	
		
			
				|  |  |  |  |     try { | 
		
	
		
			
				|  |  |  |  |       SelectDeviceByImeiRespModelElement? savedData = _appState.getSelectDeviceByImeiRespModelElement; | 
		
	
		
			
				|  |  |  |  |       LoadingUtils.hideFullScreenLoader(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |             // SelectDeviceByImeiRespModelElement savedData = SelectDeviceByImeiRespModelElement.fromJson(data); | 
		
	
		
			
				|  |  |  |  |             // setUserValues(value); | 
		
	
		
			
				|  |  |  |  |             // TODO : SavedLogin Page is not there or renamed. | 
		
	
		
			
				|  |  |  |  |             // navigationService.pushPage(page: SavedLogin(savedData)); | 
		
	
		
			
				|  |  |  |  |             // Navigator.of(context).push( | 
		
	
		
			
				|  |  |  |  |             //   MaterialPageRoute( | 
		
	
		
			
				|  |  |  |  |             //     builder: (BuildContext context) => SavedLogin(savedData), | 
		
	
		
			
				|  |  |  |  |             //   ), | 
		
	
		
			
				|  |  |  |  |             // ); | 
		
	
		
			
				|  |  |  |  |           } else { | 
		
	
		
			
				|  |  |  |  |             //Todo: Hide Loader Here | 
		
	
		
			
				|  |  |  |  |             // GifLoaderDialogUtils.hideDialog(context); | 
		
	
		
			
				|  |  |  |  |             navigationService.pushPage(page: LoginScreen()); | 
		
	
		
			
				|  |  |  |  |             // Navigator.of(context).push( | 
		
	
		
			
				|  |  |  |  |             //   MaterialPageRoute( | 
		
	
		
			
				|  |  |  |  |             //     builder: (BuildContext context) => WelcomeLogin(), | 
		
	
		
			
				|  |  |  |  |             //   ), | 
		
	
		
			
				|  |  |  |  |             // ); | 
		
	
		
			
				|  |  |  |  |           } | 
		
	
		
			
				|  |  |  |  |         }, | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  |       if (savedData != null) { | 
		
	
		
			
				|  |  |  |  |         // TODO: Navigate to SavedLogin when available | 
		
	
		
			
				|  |  |  |  |         _navigationService.pushPage(page: LoginScreen()); | 
		
	
		
			
				|  |  |  |  |         // navigationService.pushPage(page: SavedLogin(savedData)); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } catch (e) { | 
		
	
		
			
				|  |  |  |  |       log("Error handling existing IMEI data: $e"); | 
		
	
		
			
				|  |  |  |  |       LoadingUtils.hideFullScreenLoader(); | 
		
	
		
			
				|  |  |  |  |       _navigationService.pushPage(page: LoginScreen()); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> _handleNewImeiRegistration() async { | 
		
	
		
			
				|  |  |  |  |     await selectDeviceImei(onSuccess: (dynamic respData) async { | 
		
	
		
			
				|  |  |  |  |       try { | 
		
	
		
			
				|  |  |  |  |         if (respData != null) { | 
		
	
		
			
				|  |  |  |  |           dynamic data = SelectDeviceByImeiRespModelElement.fromJson(respData.toJson()); | 
		
	
		
			
				|  |  |  |  |           _appState.setSelectDeviceByImeiRespModelElement(data); | 
		
	
		
			
				|  |  |  |  |           LoadingUtils.hideFullScreenLoader(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |           // TODO: Navigate to SavedLogin when available | 
		
	
		
			
				|  |  |  |  |           // SelectDeviceByImeiRespModelElement savedData = | 
		
	
		
			
				|  |  |  |  |           //     SelectDeviceByImeiRespModelElement.fromJson(respData); | 
		
	
		
			
				|  |  |  |  |           // navigationService.pushPage(page: SavedLogin(savedData)); | 
		
	
		
			
				|  |  |  |  |           _navigationService.pushPage(page: LoginScreen()); | 
		
	
		
			
				|  |  |  |  |         } else { | 
		
	
		
			
				|  |  |  |  |           LoadingUtils.hideFullScreenLoader(); | 
		
	
		
			
				|  |  |  |  |           _navigationService.pushPage(page: LoginScreen()); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       } catch (e) { | 
		
	
		
			
				|  |  |  |  |         log("Error processing IMEI registration response: $e"); | 
		
	
		
			
				|  |  |  |  |         LoadingUtils.hideFullScreenLoader(); | 
		
	
		
			
				|  |  |  |  |         _navigationService.pushPage(page: LoginScreen()); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     }, onError: (String error) { | 
		
	
		
			
				|  |  |  |  |       LoadingUtils.hideFullScreenLoader(); | 
		
	
		
			
				|  |  |  |  |       _dialogService.showErrorDialog(message: error, onOkPressed: () {}); | 
		
	
		
			
				|  |  |  |  |     }); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> checkUserAuthentication({required OTPTypeEnum otpTypeEnum, Function(dynamic)? onSuccess, Function(String)? onError}) async { | 
		
	
		
			
				|  |  |  |  |     CheckPatientAuthenticationReq checkPatientAuthenticationReq = RequestUtils.getCommonRequestWelcome( | 
		
	
		
			
				|  |  |  |  |       phoneNumber: '0567184134', | 
		
	
		
			
				|  |  |  |  |       otpTypeEnum: OTPTypeEnum.sms, | 
		
	
		
			
				|  |  |  |  |     // TODO: THIS SHOULD BE REMOVED LATER ON AND PASSED FROM APP STATE DIRECTLY INTO API CLIENT. BECAUSE THIS API ONLY NEEDS FEW PARAMS FROM USER | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     bool isValidated = ValidationUtils.isValidatePhoneAndId( | 
		
	
		
			
				|  |  |  |  |       phoneNumber: phoneNumberController.text, | 
		
	
		
			
				|  |  |  |  |       nationalId: nationalIdController.text, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     if (!isValidated) return; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     dynamic checkPatientAuthenticationReq = RequestUtils.getCommonRequestWelcome( | 
		
	
		
			
				|  |  |  |  |       phoneNumber: phoneNumberController.text, | 
		
	
		
			
				|  |  |  |  |       nationIdText: nationalIdController.text, | 
		
	
		
			
				|  |  |  |  |       otpTypeEnum: otpTypeEnum, | 
		
	
		
			
				|  |  |  |  |       deviceToken: 'dummyDeviceToken123', | 
		
	
		
			
				|  |  |  |  |       patientOutSA: true, | 
		
	
		
			
				|  |  |  |  |       loginTokenID: 'dummyLoginToken456', | 
		
	
		
			
				|  |  |  |  |       registeredData: null, | 
		
	
		
			
				|  |  |  |  |       patientId: 12345, | 
		
	
		
			
				|  |  |  |  |       nationIdText: '1234567890', | 
		
	
		
			
				|  |  |  |  |       countryCode: 'SA', | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     final result = await authenticationRepo.checkPatientAuthentication(checkPatientAuthenticationReq: checkPatientAuthenticationReq); | 
		
	
		
			
				|  |  |  |  |     final result = await _authenticationRepo.checkPatientAuthentication(checkPatientAuthenticationReq: checkPatientAuthenticationReq); | 
		
	
		
			
				|  |  |  |  |     result.fold( | 
		
	
		
			
				|  |  |  |  |       (failure) async => await errorHandlerService.handleError(failure: failure), | 
		
	
		
			
				|  |  |  |  |       (failure) async => await _errorHandlerService.handleError(failure: failure), | 
		
	
		
			
				|  |  |  |  |       (apiResponse) { | 
		
	
		
			
				|  |  |  |  |         if (apiResponse.data['isSMSSent']) { | 
		
	
		
			
				|  |  |  |  |           // TODO:  set this in AppState | 
		
	
		
			
				|  |  |  |  |           _appState.setAppLoginToken = apiResponse.data['LogInTokenID']; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |           // sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']); | 
		
	
		
			
				|  |  |  |  |           //    loginTokenID = value['LogInTokenID'], | 
		
	
		
			
				|  |  |  |  |           // sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), | 
		
	
		
			
				|  |  |  |  |           sendActivationCode(otpTypeEnum: otpTypeEnum); | 
		
	
		
			
				|  |  |  |  |         } else { | 
		
	
		
			
				|  |  |  |  |           if (apiResponse.data['IsAuthenticated']) { | 
		
	
		
			
				|  |  |  |  |             checkActivationCode(onWrongActivationCode: (String? message) {}, activationCode: 0000); | 
		
	
		
			
				|  |  |  |  |             checkActivationCode( | 
		
	
		
			
				|  |  |  |  |               onWrongActivationCode: (String? message) {}, | 
		
	
		
			
				|  |  |  |  |               activationCode: 0000, | 
		
	
		
			
				|  |  |  |  |             ); | 
		
	
		
			
				|  |  |  |  |           } | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       }, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> sendActivationCode({ | 
		
	
		
			
				|  |  |  |  |     required OTPTypeEnum otpTypeEnum, | 
		
	
		
			
				|  |  |  |  |   }) async { | 
		
	
		
			
				|  |  |  |  |   Future<void> sendActivationCode({required OTPTypeEnum otpTypeEnum}) async { | 
		
	
		
			
				|  |  |  |  |     var request = RequestUtils.getCommonRequestAuthProvider( | 
		
	
		
			
				|  |  |  |  |       otpTypeEnum: otpTypeEnum, | 
		
	
		
			
				|  |  |  |  |       registeredData: null, | 
		
	
	
		
			
				
					|  |  |  | @ -190,13 +223,13 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |       request.isHijri = 0; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     final resultEither = await authenticationRepo.sendActivationCodeRepo( | 
		
	
		
			
				|  |  |  |  |     final resultEither = await _authenticationRepo.sendActivationCodeRepo( | 
		
	
		
			
				|  |  |  |  |       checkPatientAuthenticationReq: request, | 
		
	
		
			
				|  |  |  |  |       isRegister: isForRegister, | 
		
	
		
			
				|  |  |  |  |       languageID: 'er', | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     resultEither.fold( | 
		
	
		
			
				|  |  |  |  |       (failure) async => await errorHandlerService.handleError(failure: failure), | 
		
	
		
			
				|  |  |  |  |       (failure) async => await _errorHandlerService.handleError(failure: failure), | 
		
	
		
			
				|  |  |  |  |       (apiResponse) { | 
		
	
		
			
				|  |  |  |  |         if (apiResponse.data != null && apiResponse.data['isSMSSent'] == true) { | 
		
	
		
			
				|  |  |  |  |           // startSMSService(otpTypeEnum.toInt()); | 
		
	
	
		
			
				
					|  |  |  | @ -229,30 +262,30 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |       request['HealthId'] = healthId; | 
		
	
		
			
				|  |  |  |  |       request['IsHijri'] = isHijri; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       final resultEither = await authenticationRepo.checkActivationCodeRepo( | 
		
	
		
			
				|  |  |  |  |       final resultEither = await _authenticationRepo.checkActivationCodeRepo( | 
		
	
		
			
				|  |  |  |  |         newRequest: request, | 
		
	
		
			
				|  |  |  |  |         activationCode: activationCode.toString(), | 
		
	
		
			
				|  |  |  |  |         isRegister: true, | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  |       res = resultEither; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       resultEither.fold((failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { | 
		
	
		
			
				|  |  |  |  |       resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) { | 
		
	
		
			
				|  |  |  |  |         final activation = CheckActivationCode.fromJson(apiResponse.data as Map<String, dynamic>); | 
		
	
		
			
				|  |  |  |  |         if (registerd_data?.isRegister == true) { | 
		
	
		
			
				|  |  |  |  |           navigationService.popUntilNamed(AppRoutes.registerNewScreen); | 
		
	
		
			
				|  |  |  |  |           _navigationService.popUntilNamed(AppRoutes.registerNewScreen); | 
		
	
		
			
				|  |  |  |  |           // Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)); | 
		
	
		
			
				|  |  |  |  |           return; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       }); | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       final resultEither = await authenticationRepo.checkActivationCodeRepo( | 
		
	
		
			
				|  |  |  |  |       final resultEither = await _authenticationRepo.checkActivationCodeRepo( | 
		
	
		
			
				|  |  |  |  |         newRequest: request, | 
		
	
		
			
				|  |  |  |  |         activationCode: activationCode.toString(), | 
		
	
		
			
				|  |  |  |  |         isRegister: false, | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  |       res = resultEither; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       resultEither.fold((failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { | 
		
	
		
			
				|  |  |  |  |       resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) { | 
		
	
		
			
				|  |  |  |  |         final activation = CheckActivationCode.fromJson(resultEither as Map<String, dynamic>); | 
		
	
		
			
				|  |  |  |  |         if (activation.errorCode == '699') { | 
		
	
		
			
				|  |  |  |  |           // Todo: Hide Loader | 
		
	
	
		
			
				
					|  |  |  | @ -260,7 +293,7 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |           onWrongActivationCode(activation.errorEndUserMessage); | 
		
	
		
			
				|  |  |  |  |           return; | 
		
	
		
			
				|  |  |  |  |         } else if (registerd_data?.isRegister == true) { | 
		
	
		
			
				|  |  |  |  |           navigationService.popUntilNamed(AppRoutes.registerNewScreen); | 
		
	
		
			
				|  |  |  |  |           _navigationService.popUntilNamed(AppRoutes.registerNewScreen); | 
		
	
		
			
				|  |  |  |  |           // Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)); | 
		
	
		
			
				|  |  |  |  |           return; | 
		
	
		
			
				|  |  |  |  |         } else { | 
		
	
	
		
			
				
					|  |  |  | @ -284,7 +317,7 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> navigateToOTPScreen({required OTPTypeEnum otpTypeEnum, required String phoneNumber}) async { | 
		
	
		
			
				|  |  |  |  |     navigationService.pushToOtpScreen( | 
		
	
		
			
				|  |  |  |  |     _navigationService.pushToOtpScreen( | 
		
	
		
			
				|  |  |  |  |       phoneNumber: phoneNumber, | 
		
	
		
			
				|  |  |  |  |       checkActivationCode: (int activationCode) async { | 
		
	
		
			
				|  |  |  |  |         await checkActivationCode( | 
		
	
	
		
			
				
					|  |  |  | @ -300,4 +333,12 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |   Future<void> onWrongActivationCode({String? message}) async { | 
		
	
		
			
				|  |  |  |  |     // TODO: HANDLE THIS VIA BOTTOM SHEET | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   @override | 
		
	
		
			
				|  |  |  |  |   void dispose() { | 
		
	
		
			
				|  |  |  |  |     nationalIdController.dispose(); | 
		
	
		
			
				|  |  |  |  |     phoneNumberController.dispose(); | 
		
	
		
			
				|  |  |  |  |     myFocusNode.dispose(); | 
		
	
		
			
				|  |  |  |  |     super.dispose(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					|  |  |  | 
 |