From 7296bfb6fc3917c052826a153120aade0dd9a102 Mon Sep 17 00:00:00 2001 From: aamir-csol Date: Wed, 11 Feb 2026 11:27:26 +0300 Subject: [PATCH] family fil fixes --- .../authentication_view_model.dart | 18 +++-- .../medical_file/medical_file_view_model.dart | 27 +++---- lib/presentation/my_family/my_family.dart | 72 ++++++++++--------- .../my_family/widget/family_cards.dart | 1 + lib/services/dialog_service.dart | 28 ++++---- .../bottomsheet/exception_bottom_sheet.dart | 25 ++++--- .../family_files/family_file_add_widget.dart | 50 +++++++------ 7 files changed, 124 insertions(+), 97 deletions(-) diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index 18147a3..509b7cc 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -76,7 +76,6 @@ class AuthenticationViewModel extends ChangeNotifier { nameController = TextEditingController(), emailController = TextEditingController(); - CountryEnum selectedCountrySignup = CountryEnum.saudiArabia; MaritalStatusTypeEnum? maritalStatus; GenderTypeEnum? genderType; @@ -583,8 +582,13 @@ class AuthenticationViewModel extends ChangeNotifier { MedicalFileViewModel medicalVm = getIt(); if (!_appState.getIsChildLoggedIn) { await medicalVm.getFamilyFiles(status: 0); + if (isFormFamilyFile) { + await medicalVm.getAllPendingRecordsByResponseId(); + _navigationService.pushAndReplace(AppRoutes.medicalFilePage); + } else { + _navigationService.replaceAllRoutesAndNavigateToLanding(); + } // await medicalVm.getAllPendingRecordsByResponseId(); - _navigationService.replaceAllRoutesAndNavigateToLanding(); } } else { if (activation.list != null && activation.list!.isNotEmpty) { @@ -744,10 +748,12 @@ class AuthenticationViewModel extends ChangeNotifier { Future onWrongActivationCode({String? message}) async { otpScreenNotifier.value = true; - await _dialogService.showErrorBottomSheet(message: message ?? "Something went wrong. ", onOkPressed: () { - LoaderBottomSheet.hideLoader(); - _navigationService.pushAndReplace(AppRoutes.loginScreen); - }); + await _dialogService.showErrorBottomSheet( + message: message ?? "Something went wrong. ", + onOkPressed: () { + LoaderBottomSheet.hideLoader(); + _navigationService.pushAndReplace(AppRoutes.loginScreen); + }); } loginWithFingerPrintFace(Function success) async { diff --git a/lib/features/medical_file/medical_file_view_model.dart b/lib/features/medical_file/medical_file_view_model.dart index b26a87a..9e50075 100644 --- a/lib/features/medical_file/medical_file_view_model.dart +++ b/lib/features/medical_file/medical_file_view_model.dart @@ -439,11 +439,10 @@ class MedicalFileViewModel extends ChangeNotifier { ); // Clear and start fresh with current user - patientFamilyFiles.clear(); - patientFamilyFiles.add(currentUserFamilyFile); + final List newPatientFamilyFiles = [currentUserFamilyFile]; final List activeFamilyFiles = []; - final List pendingFamilyFiles = []; + final List newPendingFamilyFiles = []; for (var element in apiResponse.data!) { if (element.status == null) { @@ -484,7 +483,7 @@ class MedicalFileViewModel extends ChangeNotifier { if (isPending) { familyFile.isRequestFromMySide = true; - pendingFamilyFiles.add(familyFile); + newPendingFamilyFiles.add(familyFile); } if (isActive) { activeFamilyFiles.add(familyFile); @@ -492,13 +491,14 @@ class MedicalFileViewModel extends ChangeNotifier { } for (var activeFile in activeFamilyFiles) { - if (!patientFamilyFiles.any((e) => e.responseId == activeFile.responseId)) { - patientFamilyFiles.add(activeFile); + if (!newPatientFamilyFiles.any((e) => e.responseId == activeFile.responseId)) { + newPatientFamilyFiles.add(activeFile); } } - this.pendingFamilyFiles.clear(); - this.pendingFamilyFiles.addAll(pendingFamilyFiles); + // Assign new list instances + patientFamilyFiles = newPatientFamilyFiles; + pendingFamilyFiles = newPendingFamilyFiles; } notifyListeners(); @@ -553,7 +553,9 @@ class MedicalFileViewModel extends ChangeNotifier { } } // pendingFamilyFiles.addAll(tempPendingFamilyFiles.where((element) => !pendingFamilyFiles.any((e) => e.responseId == element.responseId))); - pendingFamilyFiles.addAll(tempPendingFamilyFiles.where((element) => !pendingFamilyFiles.any((e) => e.patientId == element.patientId))); + final existingIds = pendingFamilyFiles.map((e) => e.patientId).toSet(); + final newItems = tempPendingFamilyFiles.where((element) => !existingIds.contains(element.patientId)).toList(); + pendingFamilyFiles = [...pendingFamilyFiles, ...newItems]; } notifyListeners(); } @@ -589,7 +591,7 @@ class MedicalFileViewModel extends ChangeNotifier { onUnHandledFailure: (failure) { LoaderBottomSheet.hideLoader(); _dialogService.showErrorBottomSheet( - message: failure.message!, + message: failure.message, onOkPressed: () { navigationService.pop(); }); @@ -663,7 +665,7 @@ class MedicalFileViewModel extends ChangeNotifier { navigationService.pop(); }); } else if (apiResponse.messageStatus == 1) { - patientFamilyFiles.removeWhere((element) => element.id == id); + patientFamilyFiles = patientFamilyFiles.where((element) => element.id != id).toList(); getFamilyFiles(); getAllPendingRecordsByResponseId(); LoaderBottomSheet.hideLoader(); @@ -741,11 +743,12 @@ class MedicalFileViewModel extends ChangeNotifier { // moveProfile.status = 3; // moveProfile.statusDescription = "Approved"; // patientFamilyFiles.add(moveProfile); - pendingFamilyFiles.removeWhere((element) => element.id == id); + pendingFamilyFiles = pendingFamilyFiles.where((element) => element.id != id).toList(); //TODO: Call Api Here To Load Family Members getFamilyFiles(status: 0); getAllPendingRecordsByResponseId(); LoaderBottomSheet.hideLoader(); + notifyListeners(); // onFamilyFileTabChange(0); } }, diff --git a/lib/presentation/my_family/my_family.dart b/lib/presentation/my_family/my_family.dart index bac6f77..dca7574 100644 --- a/lib/presentation/my_family/my_family.dart +++ b/lib/presentation/my_family/my_family.dart @@ -1,4 +1,3 @@ - import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; @@ -20,14 +19,7 @@ import 'package:hmg_patient_app_new/widgets/custom_tab_bar.dart'; import 'package:provider/provider.dart'; class FamilyMedicalScreen extends StatefulWidget { - final List profiles; - final Function(FamilyFileResponseModelLists) onSelect; - - const FamilyMedicalScreen({ - super.key, - required this.profiles, - required this.onSelect, - }); + const FamilyMedicalScreen({super.key}); @override State createState() => _FamilyMedicalScreenState(); @@ -43,7 +35,6 @@ class _FamilyMedicalScreenState extends State { WidgetsBinding.instance.addPostFrameCallback((_) { medicalVM?.onFamilyFileTabChange(0); medicalVM?.getAllPendingRecordsByResponseId(); - }); } @@ -55,27 +46,28 @@ class _FamilyMedicalScreenState extends State { title: LocaleKeys.familyTitle.tr(context: context), bottomChild: appState.getAuthenticatedUser()!.isParentUser! ? Container( - decoration: RoundedRectangleBorder().toSmoothCornerDecoration( - color: AppColors.whiteColor, - customBorder: BorderRadius.only(topLeft: Radius.circular(24), topRight: Radius.circular(24)), - ), - padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 20.h), - child: CustomButton( - text: LocaleKeys.addANewFamilyMember.tr(context: context), - onPressed: () { - DialogService dialogService = getIt.get(); - medicalVM!.clearAuthValues(); - dialogService.showAddFamilyFileSheet( - label: LocaleKeys.addFamilyMember.tr(context: context), - message: LocaleKeys.pleaseFillBelowFieldToAddNewFamilyMember.tr(context: context), - onVerificationPress: () { - medicalVM!.addFamilyFile(otpTypeEnum: OTPTypeEnum.sms); - }); - }, - icon: AppAssets.add_icon, - fontSize: 16.f, - borderRadius: 12.r, - fontWeight: FontWeight.w500)).paddingOnly(bottom: 20.h) + decoration: RoundedRectangleBorder().toSmoothCornerDecoration( + color: AppColors.whiteColor, + customBorder: BorderRadius.only(topLeft: Radius.circular(24), topRight: Radius.circular(24)), + ), + padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 20.h), + child: CustomButton( + text: LocaleKeys.addANewFamilyMember.tr(context: context), + onPressed: () { + DialogService dialogService = getIt.get(); + medicalVM!.clearAuthValues(); + dialogService.showAddFamilyFileSheet( + label: LocaleKeys.addFamilyMember.tr(context: context), + message: LocaleKeys.pleaseFillBelowFieldToAddNewFamilyMember.tr(context: context), + onVerificationPress: () { + medicalVM!.addFamilyFile(otpTypeEnum: OTPTypeEnum.sms); + }); + }, + icon: AppAssets.add_icon, + fontSize: 16.f, + borderRadius: 12.r, + fontWeight: FontWeight.w500)) + .paddingOnly(bottom: 20.h) : SizedBox(), child: Column( mainAxisSize: MainAxisSize.min, @@ -96,18 +88,28 @@ class _FamilyMedicalScreenState extends State { ), ), appState.isChildLoggedIn ? SizedBox() : SizedBox(height: 25.h), - Selector(selector: (_, model) => model.getSelectedFamilyFileTabIndex, builder: (context, selectedIndex, child) => getFamilyTabs(index: selectedIndex)), + Selector patientFiles, List pendingFiles})>( + selector: (_, model) => (selectedIndex: model.getSelectedFamilyFileTabIndex, patientFiles: model.patientFamilyFiles, pendingFiles: model.pendingFamilyFiles), + shouldRebuild: (previous, next) { + return previous.selectedIndex != next.selectedIndex || previous.patientFiles.length != next.patientFiles.length || previous.pendingFiles.length != next.pendingFiles.length; + }, + builder: (context, data, child) => getFamilyTabs(index: data.selectedIndex, patientFiles: data.patientFiles, pendingFiles: data.pendingFiles), + ), SizedBox(height: 20.h), ], ).paddingSymmetrical(20, 0), ); } - Widget getFamilyTabs({required int index}) { + Widget getFamilyTabs({ + required int index, + required List patientFiles, + required List pendingFiles, + }) { switch (index) { case 0: return FamilyCards( - profiles: medicalVM!.patientFamilyFiles, + profiles: patientFiles, onSelect: (FamilyFileResponseModelLists profile) { medicalVM!.switchFamilyFiles(responseID: profile.responseId, patientID: profile.patientId, phoneNumber: profile.mobileNumber); }, @@ -120,7 +122,7 @@ class _FamilyMedicalScreenState extends State { ); case 1: return FamilyCards( - profiles: medicalVM!.pendingFamilyFiles, + profiles: pendingFiles, isRequestDesign: medicalVM!.getSelectedFamilyFileTabIndex == 1, onSelect: (FamilyFileResponseModelLists profile) { medicalVM!.acceptRejectFileFromFamilyMembers(id: profile.id, status: 3); diff --git a/lib/presentation/my_family/widget/family_cards.dart b/lib/presentation/my_family/widget/family_cards.dart index ea305b0..826b174 100644 --- a/lib/presentation/my_family/widget/family_cards.dart +++ b/lib/presentation/my_family/widget/family_cards.dart @@ -308,6 +308,7 @@ class _FamilyCardsState extends State { alignment: WrapAlignment.start, children: [ (profile.patientName ?? "").toText14(isBold: false, isCenter: true, maxlines: 1, weight: FontWeight.w600), + SizedBox(width: 2.w,), (getStatusTextByRequest( FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false)) .toText14( diff --git a/lib/services/dialog_service.dart b/lib/services/dialog_service.dart index 48f4159..6347a38 100644 --- a/lib/services/dialog_service.dart +++ b/lib/services/dialog_service.dart @@ -101,14 +101,18 @@ class DialogServiceImp implements DialogService { shape: const RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: Radius.circular(16)), ), - builder: (_) => ExceptionBottomSheet( - message: message, - showCancel: onCancelPressed != null ? true : false, - onOkPressed: onOkPressed, - onCancelPressed: () { - if (onCancelPressed != null) { - Navigator.of(context).pop(); - } + builder: (_) => StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return ExceptionBottomSheet( + message: message, + showCancel: onCancelPressed != null ? true : false, + onOkPressed: onOkPressed, + onCancelPressed: () { + if (onCancelPressed != null) { + Navigator.of(context).pop(); + } + }, + ); }, ), ); @@ -181,12 +185,8 @@ class DialogServiceImp implements DialogService { textColor: AppColors.primaryRedBorderColor, height: 48.h, onPressed: () { - navigationService.pushPage( - page: FamilyMedicalScreen( - profiles: profiles, - onSelect: (FamilyFileResponseModelLists p1) {}, - ), - ); + navigationService.pop(); + navigationService.pushPage(page: FamilyMedicalScreen()); }) ], ), diff --git a/lib/widgets/bottomsheet/exception_bottom_sheet.dart b/lib/widgets/bottomsheet/exception_bottom_sheet.dart index fe23264..16531bd 100644 --- a/lib/widgets/bottomsheet/exception_bottom_sheet.dart +++ b/lib/widgets/bottomsheet/exception_bottom_sheet.dart @@ -10,7 +10,7 @@ import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; -class ExceptionBottomSheet extends StatelessWidget { +class ExceptionBottomSheet extends StatefulWidget { final String? title; final String message; final bool showOKButton; @@ -28,6 +28,11 @@ class ExceptionBottomSheet extends StatelessWidget { this.onCancelPressed, }); + @override + State createState() => _ExceptionBottomSheetState(); +} + +class _ExceptionBottomSheetState extends State { @override Widget build(BuildContext context) { return SafeArea( @@ -53,7 +58,7 @@ class ExceptionBottomSheet extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - (title ?? LocaleKeys.notice.tr()).toText28(), + (widget.title ?? LocaleKeys.notice.tr()).toText28(), InkWell( onTap: () { Navigator.of(context).pop(); @@ -66,18 +71,18 @@ class ExceptionBottomSheet extends StatelessWidget { ], ), SizedBox(height: 10.h), - (message).toText16(isBold: false, color: AppColors.textColor), + (widget.message).toText16(isBold: false, color: AppColors.textColor), SizedBox(height: 10.h), SizedBox(height: 24.h), - if (showOKButton && showCancel) + if (widget.showOKButton && widget.showCancel) Row( children: [ Expanded( child: CustomButton( height: 56.h, text: LocaleKeys.cancel.tr(), - onPressed: onCancelPressed != null - ? onCancelPressed! + onPressed: widget.onCancelPressed != null + ? widget.onCancelPressed! : () { Navigator.of(context).pop(); }, @@ -92,8 +97,8 @@ class ExceptionBottomSheet extends StatelessWidget { Expanded( child: CustomButton( height: 56.h, - text: showCancel ? LocaleKeys.confirm.tr() : LocaleKeys.ok.tr(), - onPressed: onOkPressed, + text: widget.showCancel ? LocaleKeys.confirm.tr() : LocaleKeys.ok.tr(), + onPressed: widget.onOkPressed, backgroundColor: AppColors.bgGreenColor, borderColor: AppColors.bgGreenColor, textColor: Colors.white, @@ -102,13 +107,13 @@ class ExceptionBottomSheet extends StatelessWidget { ), ], ), - if (showOKButton && !showCancel) + if (widget.showOKButton && !widget.showCancel) Padding( padding: EdgeInsets.only(bottom: 10.h), child: CustomButton( height: 56.h, text: LocaleKeys.ok.tr(), - onPressed: onOkPressed, + onPressed: widget.onOkPressed, backgroundColor: AppColors.primaryRedColor, borderColor: AppColors.primaryRedBorderColor, textColor: Colors.white, diff --git a/lib/widgets/family_files/family_file_add_widget.dart b/lib/widgets/family_files/family_file_add_widget.dart index cd20c5f..15751e9 100644 --- a/lib/widgets/family_files/family_file_add_widget.dart +++ b/lib/widgets/family_files/family_file_add_widget.dart @@ -14,24 +14,29 @@ import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/dropdown/country_dropdown_widget.dart'; import 'package:hmg_patient_app_new/widgets/input_widget.dart'; +import 'package:provider/provider.dart'; -class FamilyFileAddWidget extends StatelessWidget { +class FamilyFileAddWidget extends StatefulWidget { final Function()? onVerificationPress; final String message; const FamilyFileAddWidget(this.onVerificationPress, this.message, {super.key}); + @override + State createState() => _FamilyFileAddWidgetState(); +} + +class _FamilyFileAddWidgetState extends State { @override Widget build(BuildContext context) { AuthenticationViewModel authVm = getIt.get(); - MedicalFileViewModel? medicalVM = getIt.get(); // TODO: implement build return Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - message.toText16(color: AppColors.textColor, weight: FontWeight.w500), + widget.message.toText16(color: AppColors.textColor, weight: FontWeight.w500), SizedBox(height: 20.h), Container( decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(24)), @@ -59,21 +64,26 @@ class FamilyFileAddWidget extends StatelessWidget { leadingIcon: AppAssets.student_card, ).paddingOnly(top: 8.h, bottom: 8.h), Divider(height: 1.h, color: AppColors.spacerLineColor), - TextInputWidget( - labelText: LocaleKeys.phoneNumber.tr(), - hintText: "", - controller: authVm.phoneNumberController, - isEnable: true, - prefix: authVm.selectedCountrySignup.countryCode, - isAllowRadius: true, - isBorderAllowed: false, - isAllowLeadingIcon: true, - autoFocus: true, - keyboardType: TextInputType.number, - fontFamily: "Poppins", - padding: EdgeInsets.symmetric(vertical: 8.h), - leadingIcon: AppAssets.smart_phone, - ).paddingOnly(top: 8.h, bottom: 4.h), + Selector( + selector: (_, model) => model.selectedCountrySignup.countryCode, + builder: (context, countryCode, child) { + return TextInputWidget( + labelText: LocaleKeys.phoneNumber.tr(), + hintText: "", + controller: authVm.phoneNumberController, + isEnable: true, + prefix: countryCode, + isAllowRadius: true, + isBorderAllowed: false, + isAllowLeadingIcon: true, + autoFocus: true, + keyboardType: TextInputType.number, + fontFamily: "Poppins", + padding: EdgeInsets.symmetric(vertical: 8.h), + leadingIcon: AppAssets.smart_phone, + ).paddingOnly(top: 8.h, bottom: 4.h); + }, + ), ], ), ), @@ -91,8 +101,8 @@ class FamilyFileAddWidget extends StatelessWidget { }, )) { // authVm.addFamilyMember(otpTypeEnum: OTPTypeEnum.sms, isExcludedUser: true); - if (onVerificationPress != null) { - onVerificationPress!(); + if (widget.onVerificationPress != null) { + widget.onVerificationPress!(); } } }, -- 2.30.2