diff --git a/lib/features/medical_file/medical_file_view_model.dart b/lib/features/medical_file/medical_file_view_model.dart index e0abd9d7..9f1a692d 100644 --- a/lib/features/medical_file/medical_file_view_model.dart +++ b/lib/features/medical_file/medical_file_view_model.dart @@ -431,18 +431,29 @@ class MedicalFileViewModel extends ChangeNotifier { } Future getFamilyFiles({int? status, Function(dynamic)? onSuccess, Function(String)? onError}) async { + final shouldShowLoader = patientFamilyFiles.isEmpty; + if (shouldShowLoader) { + LoaderBottomSheet.showLoader(); + } + final result = await medicalFileRepo.getPatientFamilyFiles(status, _appState.getSuperUserID != null ? _appState.getSuperUserID! : _appState.getAuthenticatedUser()!.patientId!); result.fold( (failure) async => await errorHandlerService.handleError( failure: failure, onOkPressed: () { + if (shouldShowLoader) { + LoaderBottomSheet.hideLoader(); + } onError!(failure.message); }, ), (apiResponse) { if (apiResponse.messageStatus == 2) { // _dialogService.showErrorBottomSheet(message: apiResponse.errorMessage!, onOkPressed: () {}); + if (shouldShowLoader) { + LoaderBottomSheet.hideLoader(); + } } else if (apiResponse.messageStatus == 1) { if (apiResponse.data != null) { // Add current user as the first active family file @@ -525,6 +536,9 @@ class MedicalFileViewModel extends ChangeNotifier { pendingFamilyFiles = newPendingFamilyFiles; } + if (shouldShowLoader) { + LoaderBottomSheet.hideLoader(); + } notifyListeners(); if (onSuccess != null) { onSuccess(apiResponse); @@ -662,13 +676,10 @@ class MedicalFileViewModel extends ChangeNotifier { } Future handleFamilyFileRequestOTPVerification() async { - LoaderBottomSheet.showLoader(); if (!_appState.getIsChildLoggedIn) { await getFamilyFiles(status: 0); await getAllPendingRecordsByResponseId(); } - - LoaderBottomSheet.hideLoader(); } Future removeFileFromFamilyMembers({int? id}) async { diff --git a/lib/presentation/my_family/my_family.dart b/lib/presentation/my_family/my_family.dart index 4eebc75c..62d1fb62 100644 --- a/lib/presentation/my_family/my_family.dart +++ b/lib/presentation/my_family/my_family.dart @@ -16,6 +16,7 @@ import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/custom_tab_bar.dart'; +import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart'; import 'package:provider/provider.dart'; class FamilyMedicalScreen extends StatefulWidget { @@ -32,9 +33,27 @@ class _FamilyMedicalScreenState extends State { void initState() { super.initState(); medicalVM = context.read(); - WidgetsBinding.instance.addPostFrameCallback((_) { - medicalVM?.onFamilyFileTabChange(0); - medicalVM?.getAllPendingRecordsByResponseId(); + WidgetsBinding.instance.addPostFrameCallback((_) async { + final vm = medicalVM; + if (vm == null) return; + + final shouldShowInitialLoader = vm.patientFamilyFiles.isEmpty; + if (shouldShowInitialLoader) { + LoaderBottomSheet.showLoader(); + } + + vm.onFamilyFileTabChange(0); + try { + AppState appState = getIt.get(); + if (!appState.getIsChildLoggedIn) { + await vm.getFamilyFiles(status: 0); + } + await vm.getAllPendingRecordsByResponseId(); + } finally { + if (shouldShowInitialLoader) { + LoaderBottomSheet.hideLoader(); + } + } }); } @@ -90,14 +109,22 @@ class _FamilyMedicalScreenState extends State { ), appState.isChildLoggedIn ? SizedBox() : SizedBox(height: 25.h), Selector patientFiles, List pendingFiles})>( - selector: (_, model) => (selectedIndex: model.getSelectedFamilyFileTabIndex, patientFiles: model.patientFamilyFiles, pendingFiles: model.pendingFamilyFiles), + selector: (_, model) => ( + selectedIndex: model.getSelectedFamilyFileTabIndex, + patientFiles: model.patientFamilyFiles, + pendingFiles: model.pendingFamilyFiles, + ), shouldRebuild: (previous, next) { // Only rebuild if something actually changed return previous.selectedIndex != next.selectedIndex || !identical(previous.patientFiles, next.patientFiles) || !identical(previous.pendingFiles, next.pendingFiles); }, - builder: (context, data, child) => getFamilyTabs(index: data.selectedIndex, patientFiles: data.patientFiles, pendingFiles: data.pendingFiles), + builder: (context, data, child) => getFamilyTabs( + index: data.selectedIndex, + patientFiles: data.patientFiles, + pendingFiles: data.pendingFiles, + ), ), SizedBox(height: 20.h), ], @@ -112,6 +139,7 @@ class _FamilyMedicalScreenState extends State { }) { switch (index) { case 0: + return FamilyCards( profiles: patientFiles, onSelect: (FamilyFileResponseModelLists profile) {