From 8aa152f1a0ab7ea16336e397ac3e9ad0128e60d7 Mon Sep 17 00:00:00 2001 From: faizatflutter Date: Mon, 11 May 2026 11:41:36 +0300 Subject: [PATCH] added apis --- .../refund_request/refund_request_repo.dart | 23 +- .../widgets/select_hospital_bottom_sheet.dart | 44 ++-- .../hmg_services/services_page.dart | 104 ++++---- .../refund_request_create_page.dart | 6 +- .../select_hospital_bottom_sheet_refund.dart | 223 ------------------ .../services_price_list_page.dart | 0 lib/routes/app_routes.dart | 6 +- 7 files changed, 93 insertions(+), 313 deletions(-) delete mode 100644 lib/presentation/refund_request/widgets/select_hospital_bottom_sheet_refund.dart rename lib/presentation/{servicesPriceList => service_price}/services_price_list_page.dart (100%) diff --git a/lib/features/refund_request/refund_request_repo.dart b/lib/features/refund_request/refund_request_repo.dart index e9f64d69..f8e603b6 100644 --- a/lib/features/refund_request/refund_request_repo.dart +++ b/lib/features/refund_request/refund_request_repo.dart @@ -7,8 +7,7 @@ import 'package:hmg_patient_app_new/features/refund_request/models/resp_models/r import 'package:hmg_patient_app_new/services/logger_service.dart'; abstract class RefundRequestRepo { - Future>>> - getRefundableInvoices({required int projectID}); + Future>>> getRefundableInvoices({required int projectID}); } class RefundRequestRepoImp implements RefundRequestRepo { @@ -18,8 +17,7 @@ class RefundRequestRepoImp implements RefundRequestRepo { RefundRequestRepoImp({required this.apiClient, required this.loggerService}); @override - Future>>> - getRefundableInvoices({required int projectID}) async { + Future>>> getRefundableInvoices({required int projectID}) async { // ApiClient auto-injects: PatientID, TokenID, LanguageID, PatientOutSA, // PatientTypeID, IPAdress, generalid, VersionID, Channel Map body = { @@ -38,20 +36,14 @@ class RefundRequestRepoImp implements RefundRequestRepo { }, onSuccess: (response, statusCode, {messageStatus, errorMessage}) { try { - final refundableInvoicesObject = - response['RefundableInvoicesObject']; + final refundableInvoicesObject = response['RefundableInvoicesObject']; if (refundableInvoicesObject != null) { - final invoiceItemsJson = - refundableInvoicesObject['RefundableInvoiceItems']; + final invoiceItemsJson = refundableInvoicesObject['RefundableInvoiceItems']; - final List invoicesList = - invoiceItemsJson != null - ? (invoiceItemsJson as List) - .map((item) => RefundableInvoiceItem.fromJson( - item as Map)) - .toList() - : []; + final List invoicesList = invoiceItemsJson != null + ? (invoiceItemsJson as List).map((item) => RefundableInvoiceItem.fromJson(item as Map)).toList() + : []; apiResponse = GenericApiModel>( messageStatus: messageStatus, @@ -78,4 +70,3 @@ class RefundRequestRepoImp implements RefundRequestRepo { } } } - diff --git a/lib/presentation/habib_wallet/widgets/select_hospital_bottom_sheet.dart b/lib/presentation/habib_wallet/widgets/select_hospital_bottom_sheet.dart index e93b9cef..11a2ac30 100644 --- a/lib/presentation/habib_wallet/widgets/select_hospital_bottom_sheet.dart +++ b/lib/presentation/habib_wallet/widgets/select_hospital_bottom_sheet.dart @@ -19,7 +19,12 @@ import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; class SelectHospitalBottomSheet extends StatefulWidget { - const SelectHospitalBottomSheet({super.key}); + /// Optional callback invoked when the user picks a hospital. + /// When provided, the caller handles the selection instead of the default + /// [HabibWalletViewModel.setSelectedHospital] behaviour. + final void Function(HospitalsModel hospital)? onHospitalSelected; + + const SelectHospitalBottomSheet({super.key, this.onHospitalSelected}); @override State createState() => _SelectHospitalBottomSheetState(); @@ -71,6 +76,7 @@ class _SelectHospitalBottomSheetState extends State { _updateDisplayList(); } } + habibWalletVM.addListener(listener); habibWalletVM.getProjectsList(); } @@ -195,22 +201,26 @@ class _SelectHospitalBottomSheetState extends State { child: Center(child: Utils.getLoadingWidget()), ) : SizedBox( - height: MediaQuery.sizeOf(context).height * .4, - child: ListView.separated( - itemBuilder: (_, index) { - return HospitalListItemAdvancePayment( - hospitalModel: displayList[index], - isLocationEnabled: sortByLocation, - ).onPress(() { - habibWalletVM.setSelectedHospital(displayList[index]); - Navigator.of(context).pop(); - }); - }, - separatorBuilder: (_, __) => SizedBox( - height: 16.h, - ), - itemCount: displayList.length), - ) + height: MediaQuery.sizeOf(context).height * .4, + child: ListView.separated( + itemBuilder: (_, index) { + return HospitalListItemAdvancePayment( + hospitalModel: displayList[index], + isLocationEnabled: sortByLocation, + ).onPress(() { + if (widget.onHospitalSelected != null) { + widget.onHospitalSelected!(displayList[index]); + } else { + habibWalletVM.setSelectedHospital(displayList[index]); + } + Navigator.of(context).pop(); + }); + }, + separatorBuilder: (_, __) => SizedBox( + height: 16.h, + ), + itemCount: displayList.length), + ) ], ); } diff --git a/lib/presentation/hmg_services/services_page.dart b/lib/presentation/hmg_services/services_page.dart index b2028dd8..a4a9ee10 100644 --- a/lib/presentation/hmg_services/services_page.dart +++ b/lib/presentation/hmg_services/services_page.dart @@ -30,7 +30,7 @@ import 'package:hmg_patient_app_new/presentation/home/data/landing_page_data.dar import 'package:hmg_patient_app_new/presentation/home/service_info_page.dart'; import 'package:hmg_patient_app_new/presentation/home/widgets/large_service_card.dart'; import 'package:hmg_patient_app_new/presentation/my_family/my_family.dart'; -import 'package:hmg_patient_app_new/presentation/servicesPriceList/services_price_list_page.dart'; +import 'package:hmg_patient_app_new/presentation/service_price/services_price_list_page.dart'; import 'package:hmg_patient_app_new/services/dialog_service.dart'; import 'package:hmg_patient_app_new/services/navigation_service.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; @@ -42,12 +42,12 @@ import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; -import '../../core/dependencies.dart' show getIt; +import '../../core/dependencies.dart'; class ServicesPage extends StatefulWidget { - bool showBackIcon; + final bool showBackIcon; - ServicesPage({super.key, this.showBackIcon = true}); + const ServicesPage({super.key, this.showBackIcon = true}); @override State createState() => _ServicesPageState(); @@ -560,55 +560,55 @@ class _ServicesPageState extends State { // isExpanded: false, letterSpacing: -1) // .toShimmer2(isShow: habibWalletVM.isWalletAmountLoading, radius: 12.r, width: 80.w, height: 24.h); }) - : LocaleKeys.loginToViewWalletBalance.tr().toText12(isBold: true, maxLine: 2), - Spacer(), - getIt.get().isAuthenticated - ? CustomButton( - height: 40.h, - icon: AppAssets.recharge_icon, - iconSize: 24.w, - iconColor: AppColors.infoColor, - textColor: AppColors.infoColor, - text: LocaleKeys.recharge.tr(), - borderWidth: 0.w, - isBold: true, - borderColor: Colors.transparent, - backgroundColor: Color(0xff45A2F8).withValues(alpha: 0.08), - padding: EdgeInsets.all(8.w), - fontSize: 14.f, - onPressed: () { - Navigator.of(context).push(CustomPageRoute(page: RechargeWalletPage())); - }, - ) - : SizedBox.shrink(), - ], - ).onPress(() async { - if (getIt.get().isAuthenticated) { - Navigator.of(context).push(CustomPageRoute(page: HabibWalletPage())); - } else { - await getIt.get().onLoginPressed(); - } - }), - ), - ), - SizedBox(width: 16.w), - Expanded( - child: Container( - height: 183.h, - width: 183.h, - padding: EdgeInsets.all(16.w), - decoration: RoundedRectangleBorder().toSmoothCornerDecoration( - color: AppColors.whiteColor, - borderRadius: 20.r, - hasShadow: false, + : LocaleKeys.loginToViewWalletBalance.tr().toText12(isBold: true, maxLine: 2), + Spacer(), + getIt.get().isAuthenticated + ? CustomButton( + height: 40.h, + icon: AppAssets.recharge_icon, + iconSize: 24.w, + iconColor: AppColors.infoColor, + textColor: AppColors.infoColor, + text: LocaleKeys.recharge.tr(), + borderWidth: 0.w, + isBold: true, + borderColor: Colors.transparent, + backgroundColor: Color(0xff45A2F8).withValues(alpha: 0.08), + padding: EdgeInsets.all(8.w), + fontSize: 14.f, + onPressed: () { + Navigator.of(context).push(CustomPageRoute(page: RechargeWalletPage())); + }, + ) + : SizedBox.shrink(), + ], + ).onPress(() async { + if (getIt.get().isAuthenticated) { + Navigator.of(context).push(CustomPageRoute(page: HabibWalletPage())); + } else { + await getIt.get().onLoginPressed(); + } + }), ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - spacing: 8.w, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ + ), + SizedBox(width: 16.w), + Expanded( + child: Container( + height: 183.h, + width: 183.h, + padding: EdgeInsets.all(16.w), + decoration: RoundedRectangleBorder().toSmoothCornerDecoration( + color: AppColors.whiteColor, + borderRadius: 20.r, + hasShadow: false, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + spacing: 8.w, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ Utils.buildSvgWithAssets( icon: AppAssets.services_medical_file_icon, width: 40.w, height: 40.h, applyThemeColor: false), LocaleKeys.familyTitle.tr().toText16(isBold: true, maxlines: 2).expanded, diff --git a/lib/presentation/refund_request/refund_request_create_page.dart b/lib/presentation/refund_request/refund_request_create_page.dart index 692a10a6..76ae7520 100644 --- a/lib/presentation/refund_request/refund_request_create_page.dart +++ b/lib/presentation/refund_request/refund_request_create_page.dart @@ -11,7 +11,7 @@ import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/features/habib_wallet/habib_wallet_view_model.dart'; import 'package:hmg_patient_app_new/features/refund_request/refund_request_view_model.dart'; import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; -import 'package:hmg_patient_app_new/presentation/refund_request/widgets/select_hospital_bottom_sheet_refund.dart'; +import 'package:hmg_patient_app_new/presentation/habib_wallet/widgets/select_hospital_bottom_sheet.dart'; 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'; @@ -124,7 +124,9 @@ class _RefundRequestCreatePageState extends State { context, title: LocaleKeys.selectHospital.tr(context: context), isDismissible: false, - child: SelectHospitalBottomSheetRefund(), + child: SelectHospitalBottomSheet( + onHospitalSelected: (hospital) => _vm.setSelectedHospital(hospital), + ), callBackFunc: () {}, ); }), diff --git a/lib/presentation/refund_request/widgets/select_hospital_bottom_sheet_refund.dart b/lib/presentation/refund_request/widgets/select_hospital_bottom_sheet_refund.dart deleted file mode 100644 index e38a831e..00000000 --- a/lib/presentation/refund_request/widgets/select_hospital_bottom_sheet_refund.dart +++ /dev/null @@ -1,223 +0,0 @@ -import 'package:easy_localization/easy_localization.dart'; -import 'package:flutter/material.dart'; -import 'package:hmg_patient_app_new/core/app_assets.dart'; -import 'package:hmg_patient_app_new/core/app_state.dart'; -import 'package:hmg_patient_app_new/core/dependencies.dart'; -import 'package:hmg_patient_app_new/core/location_util.dart'; -import 'package:hmg_patient_app_new/core/utils/doctor_response_mapper.dart'; -import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; -import 'package:hmg_patient_app_new/core/utils/utils.dart'; -import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; -import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; -import 'package:hmg_patient_app_new/features/habib_wallet/habib_wallet_view_model.dart'; -import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/hospital_model.dart'; -import 'package:hmg_patient_app_new/features/refund_request/refund_request_view_model.dart'; -import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; -import 'package:hmg_patient_app_new/presentation/habib_wallet/widgets/hospital_list_item.dart'; -import 'package:hmg_patient_app_new/theme/colors.dart'; -import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart'; -import 'package:permission_handler/permission_handler.dart'; -import 'package:provider/provider.dart'; - -class SelectHospitalBottomSheetRefund extends StatefulWidget { - const SelectHospitalBottomSheetRefund({super.key}); - - @override - State createState() => - _SelectHospitalBottomSheetRefundState(); -} - -class _SelectHospitalBottomSheetRefundState - extends State { - late RefundRequestViewModel refundVM; - late HabibWalletViewModel habibWalletVM; - bool sortByLocation = false; - bool isLoading = false; - List displayList = []; - - @override - void initState() { - super.initState(); - final appState = getIt.get(); - sortByLocation = (appState.userLat != 0.0) && (appState.userLong != 0.0); - WidgetsBinding.instance.addPostFrameCallback((_) { - _updateDisplayList(); - }); - } - - void _updateDisplayList() { - final appState = getIt.get(); - // Reuse the same hospital list already loaded in HabibWalletViewModel - final hospitals = List.from(habibWalletVM.advancePaymentHospitals); - - if (sortByLocation && appState.userLat != 0.0 && appState.userLong != 0.0) { - hospitals.sort((a, b) { - final distA = (a.latitude != null && a.longitude != null) - ? DoctorMapper.calculateDistance(appState.userLat, appState.userLong, - double.parse(a.latitude!), double.parse(a.longitude!)) - : double.infinity; - final distB = (b.latitude != null && b.longitude != null) - ? DoctorMapper.calculateDistance(appState.userLat, appState.userLong, - double.parse(b.latitude!), double.parse(b.longitude!)) - : double.infinity; - return distA.compareTo(distB); - }); - } - - setState(() { - displayList = hospitals; - isLoading = false; - }); - } - - void _refreshHospitalListAfterApi() { - void listener() { - if (habibWalletVM.advancePaymentHospitals.isNotEmpty) { - habibWalletVM.removeListener(listener); - _updateDisplayList(); - } - } - habibWalletVM.addListener(listener); - habibWalletVM.getProjectsList(); - } - - void _handleSortByLocationToggle(bool value) { - if (value) { - final locationUtils = getIt.get(); - locationUtils.getLocation( - isShowConfirmDialog: true, - onSuccess: (latLng) { - setState(() { - sortByLocation = true; - isLoading = true; - }); - _refreshHospitalListAfterApi(); - }, - onFailure: () { - showCommonBottomSheetWithoutHeight( - title: LocaleKeys.notice.tr(context: context), - context, - child: Utils.getWarningWidget( - loadingText: LocaleKeys.giveLocationPermissionForNearestList - .tr(context: context), - isShowActionButtons: true, - onCancelTap: () => Navigator.of(context).pop(), - onConfirmTap: () async { - Navigator.of(context).pop(); - openAppSettings(); - }, - ), - callBackFunc: () {}, - isFullScreen: false, - isCloseButtonVisible: true, - ); - setState(() => sortByLocation = false); - }, - onLocationDeniedForever: () { - showCommonBottomSheetWithoutHeight( - title: LocaleKeys.notice.tr(context: context), - context, - child: Utils.getWarningWidget( - loadingText: LocaleKeys.giveLocationPermissionForNearestList - .tr(context: context), - isShowActionButtons: true, - onCancelTap: () => Navigator.of(context).pop(), - onConfirmTap: () async { - Navigator.of(context).pop(); - openAppSettings(); - }, - ), - callBackFunc: () {}, - isFullScreen: false, - isCloseButtonVisible: true, - ); - setState(() => sortByLocation = false); - }, - ); - } else { - final appState = getIt.get(); - appState.resetLocation(); - setState(() { - sortByLocation = false; - isLoading = true; - }); - _refreshHospitalListAfterApi(); - } - } - - @override - Widget build(BuildContext context) { - refundVM = context.read(); - habibWalletVM = context.read(); - - if (displayList.isEmpty && habibWalletVM.advancePaymentHospitals.isNotEmpty) { - displayList = List.from(habibWalletVM.advancePaymentHospitals); - } - - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - LocaleKeys.selectHospitalForAdvancePayment - .tr(context: context) - .toText16(color: AppColors.greyTextColor, isBold: true), - SizedBox(height: 16.h), - Padding( - padding: EdgeInsets.symmetric(horizontal: 4.w), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( - children: [ - Utils.buildSvgWithAssets( - icon: AppAssets.location, - iconColor: AppColors.greyTextColor, - width: 18.h, - height: 18.h), - SizedBox(width: 8.w), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - LocaleKeys.sortByLocation.tr(context: context).toText14(isBold: true), - LocaleKeys.sortByNearestLocation - .tr(context: context) - .toText11(color: AppColors.textColorLight, isBold: true), - ], - ), - ], - ), - Switch( - value: sortByLocation, - onChanged: _handleSortByLocationToggle, - activeThumbColor: AppColors.successColor, - activeTrackColor: AppColors.successColor.withValues(alpha: 0.15), - ), - ], - ), - ), - SizedBox(height: 8.h), - isLoading - ? SizedBox( - height: MediaQuery.sizeOf(context).height * .4, - child: Center(child: Utils.getLoadingWidget()), - ) - : SizedBox( - height: MediaQuery.sizeOf(context).height * .4, - child: ListView.separated( - itemCount: displayList.length, - separatorBuilder: (_, __) => SizedBox(height: 16.h), - itemBuilder: (_, index) { - return HospitalListItemAdvancePayment( - hospitalModel: displayList[index], - isLocationEnabled: sortByLocation, - ).onPress(() { - refundVM.setSelectedHospital(displayList[index]); - Navigator.of(context).pop(); - }); - }, - ), - ), - ], - ); - } -} - diff --git a/lib/presentation/servicesPriceList/services_price_list_page.dart b/lib/presentation/service_price/services_price_list_page.dart similarity index 100% rename from lib/presentation/servicesPriceList/services_price_list_page.dart rename to lib/presentation/service_price/services_price_list_page.dart diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index 7b34e447..9170e039 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -19,7 +19,9 @@ import 'package:hmg_patient_app_new/presentation/home/navigation_screen.dart'; import 'package:hmg_patient_app_new/presentation/home_health_care/hhc_procedures_page.dart'; import 'package:hmg_patient_app_new/presentation/medical_file/medical_file_page.dart'; import 'package:hmg_patient_app_new/presentation/my_family/my_family.dart'; -import 'package:hmg_patient_app_new/presentation/servicesPriceList/services_price_list_page.dart'; +import 'package:hmg_patient_app_new/presentation/parking/paking_page.dart'; +import 'package:hmg_patient_app_new/presentation/refund_request/refund_request_create_page.dart'; +import 'package:hmg_patient_app_new/presentation/service_price/services_price_list_page.dart'; import 'package:hmg_patient_app_new/presentation/smartwatches/smartwatch_home_page.dart'; import 'package:hmg_patient_app_new/presentation/symptoms_checker/organ_selector_screen.dart'; import 'package:hmg_patient_app_new/presentation/symptoms_checker/possible_conditions_screen.dart'; @@ -41,8 +43,6 @@ import '../core/dependencies.dart'; import '../features/monthly_reports/monthly_reports_repo.dart'; import '../features/monthly_reports/monthly_reports_view_model.dart'; import '../features/qr_parking/qr_parking_view_model.dart'; -import 'package:hmg_patient_app_new/presentation/parking/paking_page.dart'; -import 'package:hmg_patient_app_new/presentation/refund_request/refund_request_create_page.dart'; import '../services/error_handler_service.dart'; class AppRoutes {