dev_sultan #349

Merged
Haroon6138 merged 3 commits from dev_sultan into master 4 days ago

@ -29,7 +29,11 @@ class MedicalFileViewModel extends ChangeNotifier {
bool isPatientSickLeavePDFLoading = false; bool isPatientSickLeavePDFLoading = false;
bool isPatientMedicalReportsListLoading = false; bool isPatientMedicalReportsListLoading = false;
bool isPatientAllergiesListLoading = false; bool isPatientAllergiesListLoading = false;
bool _isFamilyFilesLoading = false;
bool get isFamilyFilesLoading => _isFamilyFilesLoading;
set setIsFamilyFilesLoading(bool value) => _isFamilyFilesLoading = value;
MedicalFileRepo medicalFileRepo; MedicalFileRepo medicalFileRepo;
ErrorHandlerService errorHandlerService; ErrorHandlerService errorHandlerService;
@ -431,21 +435,42 @@ class MedicalFileViewModel extends ChangeNotifier {
} }
Future<void> getFamilyFiles({int? status, Function(dynamic)? onSuccess, Function(String)? onError}) async { 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!); final result = await medicalFileRepo.getPatientFamilyFiles(status, _appState.getSuperUserID != null ? _appState.getSuperUserID! : _appState.getAuthenticatedUser()!.patientId!);
result.fold( result.fold(
(failure) async => await errorHandlerService.handleError( (failure) async {
setIsFamilyFilesLoading = false;
await errorHandlerService.handleError(
failure: failure, failure: failure,
onOkPressed: () { onOkPressed: () {
if (shouldShowLoader) {
LoaderBottomSheet.hideLoader();
}
onError!(failure.message); onError!(failure.message);
}, },
), );
},
(apiResponse) { (apiResponse) {
if (apiResponse.messageStatus == 2) { if (apiResponse.messageStatus == 2) {
setIsFamilyFilesLoading = false;
// _dialogService.showErrorBottomSheet(message: apiResponse.errorMessage!, onOkPressed: () {}); // _dialogService.showErrorBottomSheet(message: apiResponse.errorMessage!, onOkPressed: () {});
if (shouldShowLoader) {
LoaderBottomSheet.hideLoader();
}
} else if (apiResponse.messageStatus == 1) { } else if (apiResponse.messageStatus == 1) {
if (apiResponse.data != null) { if (apiResponse.data != null) {
// Add current user as the first active family file
final currentUser = _appState.getAuthenticatedUser()!; final currentUser = _appState.getAuthenticatedUser()!;
final currentUserFamilyFile = FamilyFileResponseModelLists( final currentUserFamilyFile = FamilyFileResponseModelLists(
patientId: currentUser.patientId, patientId: currentUser.patientId,
@ -525,6 +550,12 @@ class MedicalFileViewModel extends ChangeNotifier {
pendingFamilyFiles = newPendingFamilyFiles; pendingFamilyFiles = newPendingFamilyFiles;
} }
// Clear loading state on success
setIsFamilyFilesLoading = false;
if (shouldShowLoader) {
LoaderBottomSheet.hideLoader();
}
notifyListeners(); notifyListeners();
if (onSuccess != null) { if (onSuccess != null) {
onSuccess(apiResponse); onSuccess(apiResponse);
@ -662,13 +693,10 @@ class MedicalFileViewModel extends ChangeNotifier {
} }
Future<void> handleFamilyFileRequestOTPVerification() async { Future<void> handleFamilyFileRequestOTPVerification() async {
LoaderBottomSheet.showLoader();
if (!_appState.getIsChildLoggedIn) { if (!_appState.getIsChildLoggedIn) {
await getFamilyFiles(status: 0); await getFamilyFiles(status: 0);
await getAllPendingRecordsByResponseId(); await getAllPendingRecordsByResponseId();
} }
LoaderBottomSheet.hideLoader();
} }
Future<void> removeFileFromFamilyMembers({int? id}) async { 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/appbar/collapsing_list_view.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.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/custom_tab_bar.dart';
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class FamilyMedicalScreen extends StatefulWidget { class FamilyMedicalScreen extends StatefulWidget {
@ -32,9 +33,15 @@ class _FamilyMedicalScreenState extends State<FamilyMedicalScreen> {
void initState() { void initState() {
super.initState(); super.initState();
medicalVM = context.read<MedicalFileViewModel>(); medicalVM = context.read<MedicalFileViewModel>();
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) async {
if(medicalVM!.isFamilyFilesLoading) {
LoaderBottomSheet.showLoader();
} else {
LoaderBottomSheet.hideLoader();
}
medicalVM?.onFamilyFileTabChange(0); medicalVM?.onFamilyFileTabChange(0);
medicalVM?.getAllPendingRecordsByResponseId(); medicalVM?.getAllPendingRecordsByResponseId();
}); });
} }
@ -90,14 +97,22 @@ class _FamilyMedicalScreenState extends State<FamilyMedicalScreen> {
), ),
appState.isChildLoggedIn ? SizedBox() : SizedBox(height: 25.h), appState.isChildLoggedIn ? SizedBox() : SizedBox(height: 25.h),
Selector<MedicalFileViewModel, ({int selectedIndex, List<FamilyFileResponseModelLists> patientFiles, List<FamilyFileResponseModelLists> pendingFiles})>( 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) { shouldRebuild: (previous, next) {
// Only rebuild if something actually changed // Only rebuild if something actually changed
return previous.selectedIndex != next.selectedIndex || return previous.selectedIndex != next.selectedIndex ||
!identical(previous.patientFiles, next.patientFiles) || !identical(previous.patientFiles, next.patientFiles) ||
!identical(previous.pendingFiles, next.pendingFiles); !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), SizedBox(height: 20.h),
], ],
@ -112,6 +127,7 @@ class _FamilyMedicalScreenState extends State<FamilyMedicalScreen> {
}) { }) {
switch (index) { switch (index) {
case 0: case 0:
return FamilyCards( return FamilyCards(
profiles: patientFiles, profiles: patientFiles,
onSelect: (FamilyFileResponseModelLists profile) { onSelect: (FamilyFileResponseModelLists profile) {

Loading…
Cancel
Save