Merge branch 'master' into haroon_dev

haroon_dev
haroon amjad 22 hours ago
commit b1f2858c0c

@ -29,7 +29,11 @@ class MedicalFileViewModel extends ChangeNotifier {
bool isPatientSickLeavePDFLoading = false;
bool isPatientMedicalReportsListLoading = false;
bool isPatientAllergiesListLoading = false;
bool _isFamilyFilesLoading = false;
bool get isFamilyFilesLoading => _isFamilyFilesLoading;
set setIsFamilyFilesLoading(bool value) => _isFamilyFilesLoading = value;
MedicalFileRepo medicalFileRepo;
ErrorHandlerService errorHandlerService;
@ -431,21 +435,42 @@ class MedicalFileViewModel extends ChangeNotifier {
}
Future<void> getFamilyFiles({int? status, Function(dynamic)? onSuccess, Function(String)? onError}) async {
setIsFamilyFilesLoading = true;
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: () {
onError!(failure.message);
},
),
(failure) async {
setIsFamilyFilesLoading = false;
await errorHandlerService.handleError(
failure: failure,
onOkPressed: () {
if (shouldShowLoader) {
LoaderBottomSheet.hideLoader();
}
onError!(failure.message);
},
);
},
(apiResponse) {
if (apiResponse.messageStatus == 2) {
setIsFamilyFilesLoading = false;
// _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
final currentUser = _appState.getAuthenticatedUser()!;
final currentUserFamilyFile = FamilyFileResponseModelLists(
patientId: currentUser.patientId,
@ -525,6 +550,12 @@ class MedicalFileViewModel extends ChangeNotifier {
pendingFamilyFiles = newPendingFamilyFiles;
}
// Clear loading state on success
setIsFamilyFilesLoading = false;
if (shouldShowLoader) {
LoaderBottomSheet.hideLoader();
}
notifyListeners();
if (onSuccess != null) {
onSuccess(apiResponse);
@ -662,13 +693,10 @@ class MedicalFileViewModel extends ChangeNotifier {
}
Future<void> handleFamilyFileRequestOTPVerification() async {
LoaderBottomSheet.showLoader();
if (!_appState.getIsChildLoggedIn) {
await getFamilyFiles(status: 0);
await getAllPendingRecordsByResponseId();
}
LoaderBottomSheet.hideLoader();
}
Future<void> removeFileFromFamilyMembers({int? id}) async {

@ -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,15 @@ class _FamilyMedicalScreenState extends State<FamilyMedicalScreen> {
void initState() {
super.initState();
medicalVM = context.read<MedicalFileViewModel>();
WidgetsBinding.instance.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
if(medicalVM!.isFamilyFilesLoading) {
LoaderBottomSheet.showLoader();
} else {
LoaderBottomSheet.hideLoader();
}
medicalVM?.onFamilyFileTabChange(0);
medicalVM?.getAllPendingRecordsByResponseId();
});
}
@ -90,14 +97,22 @@ class _FamilyMedicalScreenState extends State<FamilyMedicalScreen> {
),
appState.isChildLoggedIn ? SizedBox() : SizedBox(height: 25.h),
Selector<MedicalFileViewModel, ({int selectedIndex, List<FamilyFileResponseModelLists> patientFiles, List<FamilyFileResponseModelLists> 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 +127,7 @@ class _FamilyMedicalScreenState extends State<FamilyMedicalScreen> {
}) {
switch (index) {
case 0:
return FamilyCards(
profiles: patientFiles,
onSelect: (FamilyFileResponseModelLists profile) {

Loading…
Cancel
Save