From dfd7160030e52abda8a72f108a66852fa4fe61c7 Mon Sep 17 00:00:00 2001 From: aamir-csol Date: Sun, 26 Apr 2026 11:41:03 +0300 Subject: [PATCH] Medical File Navigation & Keyboard Fix --- .../authentication_view_model.dart | 31 ++++++------------- lib/services/navigation_service.dart | 19 ++++++------ .../family_files/family_file_add_widget.dart | 8 +++-- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index 6b209b67..8e2d2b47 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -368,11 +368,7 @@ class AuthenticationViewModel extends ChangeNotifier { } else if (apiResponse.messageStatus == 1) { if (apiResponse.data['isSMSSent']) { _appState.setAppAuthToken = apiResponse.data['LogInTokenID']; - await sendActivationCode( - otpTypeEnum: otpTypeEnum, - phoneNumber: phoneNumberController.text, - nationalIdOrFileNumber: nationalIdController.text, - isForRegister: false); + await sendActivationCode(otpTypeEnum: otpTypeEnum, phoneNumber: phoneNumberController.text, nationalIdOrFileNumber: nationalIdController.text, isForRegister: false); } else { if (apiResponse.data['IsAuthenticated']) { await checkActivationCode( @@ -434,10 +430,7 @@ class AuthenticationViewModel extends ChangeNotifier { } final resultEither = await _authenticationRepo.sendActivationCodeRepo( - sendActivationCodeReq: request, - isRegister: checkIsUserComingForRegister(request: payload), - languageID: 'er', - isFormFamilyFile: isFormFamilyFile); + sendActivationCodeReq: request, isRegister: checkIsUserComingForRegister(request: payload), languageID: 'er', isFormFamilyFile: isFormFamilyFile); resultEither.fold( (failure) async => await _errorHandlerService.handleError(failure: failure), @@ -514,9 +507,7 @@ class AuthenticationViewModel extends ChangeNotifier { bool isSwitchUser = false, int? patientID, }) async { - bool isForRegister = (_appState.getUserRegistrationPayload.healthId != null || - _appState.getUserRegistrationPayload.patientOutSa == true || - _appState.getUserRegistrationPayload.patientOutSa == 1); + bool isForRegister = (_appState.getUserRegistrationPayload.healthId != null || _appState.getUserRegistrationPayload.patientOutSa == true || _appState.getUserRegistrationPayload.patientOutSa == 1); MyAppointmentsViewModel myAppointmentsVM = getIt(); if (isSwitchUser && _appState.getSuperUserID == null) { @@ -558,8 +549,7 @@ class AuthenticationViewModel extends ChangeNotifier { request["ForRegisteration"] = _appState.getUserRegistrationPayload.isRegister; request["isRegister"] = false; - final resultEither = - await _authenticationRepo.checkActivationCodeRepo(newRequest: request, activationCode: activationCode.toString(), isRegister: true); + final resultEither = await _authenticationRepo.checkActivationCodeRepo(newRequest: request, activationCode: activationCode.toString(), isRegister: true); LoaderBottomSheet.hideLoader(); @@ -633,7 +623,9 @@ class AuthenticationViewModel extends ChangeNotifier { await medicalVm.getFamilyFiles(status: 0); if (isFormFamilyFile) { await medicalVm.getAllPendingRecordsByResponseId(); - _navigationService.pushAndReplace(AppRoutes.medicalFilePage); + _navigationService.replaceAllRoutesAndNavigateToLandingWithMedicalAuth().whenComplete(() { + _navigationService.pushPageRoute(AppRoutes.medicalFilePage); + }); } else { _navigationService.replaceAllRoutesAndNavigateToLanding(); } @@ -870,8 +862,7 @@ class AuthenticationViewModel extends ChangeNotifier { : _appState.getAuthenticatedUser()!.mobileNumber)!; nationalIdController.text = _appState.getAuthenticatedUser()!.patientIdentificationNo!; onSuccess(); - } else if ((loginTypeEnum == LoginTypeEnum.sms || - loginTypeEnum == LoginTypeEnum.whatsapp && _appState.getSelectDeviceByImeiRespModelElement == null) && + } else if ((loginTypeEnum == LoginTypeEnum.sms || loginTypeEnum == LoginTypeEnum.whatsapp && _appState.getSelectDeviceByImeiRespModelElement == null) && _appState.getAuthenticatedUser() != null) { phoneNumberController.text = (_appState.getAuthenticatedUser()!.mobileNumber!.startsWith("0") ? _appState.getAuthenticatedUser()!.mobileNumber!.replaceFirst("0", "") @@ -928,8 +919,7 @@ class AuthenticationViewModel extends ChangeNotifier { LoaderBottomSheet.showLoader(); // LoadingUtils.showFullScreenLoader(loadingText: "Setting up your medical file.\nMay take a moment."); - var request = RequestUtils.getUserSignupCompletionRequest( - fullName: nameController.text, emailAddress: emailController.text, gender: genderType, maritalStatus: maritalStatus); + var request = RequestUtils.getUserSignupCompletionRequest(fullName: nameController.text, emailAddress: emailController.text, gender: genderType, maritalStatus: maritalStatus); final resultEither = await _authenticationRepo.registerUser(registrationPayloadDataModelRequest: request); resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { @@ -1059,8 +1049,7 @@ class AuthenticationViewModel extends ChangeNotifier { biometricEnabled: loginType == 1 || loginType == 2 ? false : true, firstNameN: _appState.getAuthenticatedUser()!.firstNameN, lastNameN: _appState.getAuthenticatedUser()!.lastNameN, - zipCode: - _appState.getAuthenticatedUser()!.zipCode //selectedCountrySignup == CountryEnum.others ? '0': selectedCountrySignup.countryCode, + zipCode: _appState.getAuthenticatedUser()!.zipCode //selectedCountrySignup == CountryEnum.others ? '0': selectedCountrySignup.countryCode, ) .toJson()); resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { diff --git a/lib/services/navigation_service.dart b/lib/services/navigation_service.dart index da4a75b9..3f0fb2a1 100644 --- a/lib/services/navigation_service.dart +++ b/lib/services/navigation_service.dart @@ -25,6 +25,7 @@ class NavigationService { navigatorKey.currentState?.popUntil(ModalRoute.withName(routeName)); } + void replaceAllRoutesAndNavigateToLanding() { AppState appState = getIt.get(); appState.isAuthenticated = false; @@ -34,6 +35,13 @@ class NavigationService { ); } + Future replaceAllRoutesAndNavigateToLandingWithMedicalAuth() async { + navigatorKey.currentState?.pushNamedAndRemoveUntil( + AppRoutes.landingScreen, + (Route route) => false, + ); + } + void replaceAllRoutesAndNavigateToLandingAuth() { navigatorKey.currentState?.pushNamedAndRemoveUntil( AppRoutes.landingScreen, @@ -50,17 +58,10 @@ class NavigationService { } Future pushToOtpScreen( - {required String phoneNumber, - required Function(int code) checkActivationCode, - required Function(String phoneNumber) onResendOTPPressed, - bool isFormFamilyFile = false}) { + {required String phoneNumber, required Function(int code) checkActivationCode, required Function(String phoneNumber) onResendOTPPressed, bool isFormFamilyFile = false}) { return navigatorKey.currentState!.push( MaterialPageRoute( - builder: (_) => OTPVerificationScreen( - phoneNumber: phoneNumber, - checkActivationCode: checkActivationCode, - onResendOTPPressed: onResendOTPPressed, - isFormFamilyFile: isFormFamilyFile)), + builder: (_) => OTPVerificationScreen(phoneNumber: phoneNumber, checkActivationCode: checkActivationCode, onResendOTPPressed: onResendOTPPressed, isFormFamilyFile: isFormFamilyFile)), ); } diff --git a/lib/widgets/family_files/family_file_add_widget.dart b/lib/widgets/family_files/family_file_add_widget.dart index 92a14fd8..429b7f4e 100644 --- a/lib/widgets/family_files/family_file_add_widget.dart +++ b/lib/widgets/family_files/family_file_add_widget.dart @@ -57,7 +57,7 @@ class _FamilyFileAddWidgetState extends State { isAllowRadius: true, isBorderAllowed: false, isAllowLeadingIcon: true, - autoFocus: true, + autoFocus: false, keyboardType: TextInputType.number, fontFamily: "Poppins", padding: EdgeInsets.symmetric(vertical: 8.h), @@ -76,7 +76,7 @@ class _FamilyFileAddWidgetState extends State { isAllowRadius: true, isBorderAllowed: false, isAllowLeadingIcon: true, - autoFocus: true, + autoFocus: false, keyboardType: TextInputType.number, fontFamily: "Poppins", padding: EdgeInsets.symmetric(vertical: 8.h), @@ -91,7 +91,9 @@ class _FamilyFileAddWidgetState extends State { CustomButton( text: LocaleKeys.add.tr(context: context), onPressed: () { - FocusScope.of(context).unfocus(); + // Unfocus all text fields and dismiss keyboard + FocusManager.instance.primaryFocus?.unfocus(); + if (ValidationUtils.isValidatedIdAndPhoneWithCountryValidation( nationalId: authVm.nationalIdController.text, selectedCountry: authVm.selectedCountrySignup,