added apis
parent
7cf593443d
commit
8aa152f1a0
@ -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<SelectHospitalBottomSheetRefund> createState() =>
|
||||
_SelectHospitalBottomSheetRefundState();
|
||||
}
|
||||
|
||||
class _SelectHospitalBottomSheetRefundState
|
||||
extends State<SelectHospitalBottomSheetRefund> {
|
||||
late RefundRequestViewModel refundVM;
|
||||
late HabibWalletViewModel habibWalletVM;
|
||||
bool sortByLocation = false;
|
||||
bool isLoading = false;
|
||||
List<HospitalsModel> displayList = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final appState = getIt.get<AppState>();
|
||||
sortByLocation = (appState.userLat != 0.0) && (appState.userLong != 0.0);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_updateDisplayList();
|
||||
});
|
||||
}
|
||||
|
||||
void _updateDisplayList() {
|
||||
final appState = getIt.get<AppState>();
|
||||
// Reuse the same hospital list already loaded in HabibWalletViewModel
|
||||
final hospitals = List<HospitalsModel>.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>();
|
||||
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>();
|
||||
appState.resetLocation();
|
||||
setState(() {
|
||||
sortByLocation = false;
|
||||
isLoading = true;
|
||||
});
|
||||
_refreshHospitalListAfterApi();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
refundVM = context.read<RefundRequestViewModel>();
|
||||
habibWalletVM = context.read<HabibWalletViewModel>();
|
||||
|
||||
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();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue