|
|
|
|
@ -3,6 +3,9 @@ import 'dart:async';
|
|
|
|
|
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/size_utils.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart' show Utils;
|
|
|
|
|
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
|
|
|
|
@ -14,6 +17,7 @@ import 'package:hmg_patient_app_new/presentation/appointments/widgets/region_bot
|
|
|
|
|
import 'package:hmg_patient_app_new/theme/colors.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
|
|
|
|
|
import 'package:lottie/lottie.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
|
|
|
|
|
|
@ -33,6 +37,7 @@ class _RegionBottomSheetBodyState extends State<RegionBottomSheetBody> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
scheduleMicrotask(() {
|
|
|
|
|
regionalViewModel.initSortByLocation();
|
|
|
|
|
if (regionalViewModel.regionBottomSheetType == RegionBottomSheetType.FOR_REGION || regionalViewModel.regionBottomSheetType == RegionBottomSheetType.REGION_FOR_DENTAL_AND_LASER ) {
|
|
|
|
|
myAppointmentsViewModel.getRegionMappedProjectList();
|
|
|
|
|
} else if (regionalViewModel.regionBottomSheetType == RegionBottomSheetType.FOR_CLINIIC) {
|
|
|
|
|
@ -110,30 +115,128 @@ class _RegionBottomSheetBodyState extends State<RegionBottomSheetBody> {
|
|
|
|
|
} else {
|
|
|
|
|
return SizedBox(
|
|
|
|
|
height: MediaQuery.of(context).size.height * 0.5,
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
itemCount: myAppointmentsVM.hospitalList?.registeredDoctorMap?.length ?? 0,
|
|
|
|
|
separatorBuilder: (_, __) {
|
|
|
|
|
return SizedBox(
|
|
|
|
|
height: 16.h,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
itemBuilder: (_, index) {
|
|
|
|
|
String key = myAppointmentsVM.hospitalList?.registeredDoctorMap?.keys.toList()[index] ?? '';
|
|
|
|
|
return RegionListItem(
|
|
|
|
|
title: key,
|
|
|
|
|
subTitle: "",
|
|
|
|
|
hmcCount: "${myAppointmentsVM.hospitalList?.registeredDoctorMap?[key]?.hmcSize ?? 0}",
|
|
|
|
|
hmgCount: "${myAppointmentsVM.hospitalList?.registeredDoctorMap?[key]?.hmgSize ?? 0}",
|
|
|
|
|
).onPress(() {
|
|
|
|
|
regionalViewModel.setSelectedRegionId(key);
|
|
|
|
|
regionalViewModel.setDisplayListAndRegionHospitalList(myAppointmentsVM.hospitalList?.registeredDoctorMap![key]);
|
|
|
|
|
regionalViewModel.setBottomSheetState(AppointmentViaRegionState.HOSPITAL_SELECTION);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Consumer<AppointmentViaRegionViewmodel>(
|
|
|
|
|
builder: (context, regionVM, _) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 8.h),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Utils.buildSvgWithAssets(icon: AppAssets.location, iconColor: AppColors.greyTextColor, width: 24.h, height: 24.h),
|
|
|
|
|
SizedBox(width: 12.w),
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
LocaleKeys.sortByLocation.tr(context: context).toText14(isBold: true),
|
|
|
|
|
// SizedBox(height: 4.h),
|
|
|
|
|
LocaleKeys.sortByNearestLocation.tr(context: context).toText11(color: AppColors.textColorLight, weight: FontWeight.w500),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
Switch(
|
|
|
|
|
value: regionVM.sortByLocation,
|
|
|
|
|
onChanged: (value) => _handleSortByLocationToggle(value),
|
|
|
|
|
activeThumbColor: AppColors.successColor,
|
|
|
|
|
activeTrackColor: AppColors.successColor.withValues(alpha: 0.15),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
itemCount: myAppointmentsVM.hospitalList?.registeredDoctorMap?.length ?? 0,
|
|
|
|
|
separatorBuilder: (_, __) {
|
|
|
|
|
return SizedBox(
|
|
|
|
|
height: 16.h,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
itemBuilder: (_, index) {
|
|
|
|
|
String key = myAppointmentsVM.hospitalList?.registeredDoctorMap?.keys.toList()[index] ?? '';
|
|
|
|
|
return RegionListItem(
|
|
|
|
|
title: key,
|
|
|
|
|
subTitle: "",
|
|
|
|
|
hmcCount: "${myAppointmentsVM.hospitalList?.registeredDoctorMap?[key]?.hmcSize ?? 0}",
|
|
|
|
|
hmgCount: "${myAppointmentsVM.hospitalList?.registeredDoctorMap?[key]?.hmgSize ?? 0}",
|
|
|
|
|
).onPress(() {
|
|
|
|
|
regionalViewModel.setSelectedRegionId(key);
|
|
|
|
|
regionalViewModel.setDisplayListAndRegionHospitalList(myAppointmentsVM.hospitalList?.registeredDoctorMap![key]);
|
|
|
|
|
regionalViewModel.setBottomSheetState(AppointmentViaRegionState.HOSPITAL_SELECTION);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _handleSortByLocationToggle(bool value) {
|
|
|
|
|
if (value) {
|
|
|
|
|
// User wants to sort by location — check permission & get location
|
|
|
|
|
final locationUtils = getIt.get<LocationUtils>();
|
|
|
|
|
locationUtils.getLocation(
|
|
|
|
|
isShowConfirmDialog: true,
|
|
|
|
|
onSuccess: (latLng) {
|
|
|
|
|
regionalViewModel.setSortByLocation(true);
|
|
|
|
|
myAppointmentsViewModel.getRegionMappedProjectList();
|
|
|
|
|
},
|
|
|
|
|
onFailure: () {
|
|
|
|
|
showCommonBottomSheetWithoutHeight(
|
|
|
|
|
title: LocaleKeys.notice.tr(context: context),
|
|
|
|
|
context,
|
|
|
|
|
child: Utils.getWarningWidget(
|
|
|
|
|
loadingText: "Please grant location permission from app settings to see better results",
|
|
|
|
|
isShowActionButtons: true,
|
|
|
|
|
onCancelTap: () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
},
|
|
|
|
|
onConfirmTap: () async {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
openAppSettings();
|
|
|
|
|
}),
|
|
|
|
|
callBackFunc: () {},
|
|
|
|
|
isFullScreen: false,
|
|
|
|
|
isCloseButtonVisible: true,
|
|
|
|
|
);
|
|
|
|
|
regionalViewModel.setSortByLocation(false);
|
|
|
|
|
},
|
|
|
|
|
onLocationDeniedForever: () {
|
|
|
|
|
showCommonBottomSheetWithoutHeight(
|
|
|
|
|
title: LocaleKeys.notice.tr(context: context),
|
|
|
|
|
context,
|
|
|
|
|
child: Utils.getWarningWidget(
|
|
|
|
|
loadingText: "Please grant location permission from app settings to see better results",
|
|
|
|
|
isShowActionButtons: true,
|
|
|
|
|
onCancelTap: () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
},
|
|
|
|
|
onConfirmTap: () async {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
openAppSettings();
|
|
|
|
|
}),
|
|
|
|
|
callBackFunc: () {},
|
|
|
|
|
isFullScreen: false,
|
|
|
|
|
isCloseButtonVisible: true,
|
|
|
|
|
);
|
|
|
|
|
regionalViewModel.setSortByLocation(false);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// User turned off sort by location — reset location & re-fetch
|
|
|
|
|
final appState = getIt.get<AppState>();
|
|
|
|
|
appState.resetLocation();
|
|
|
|
|
regionalViewModel.setSortByLocation(false);
|
|
|
|
|
myAppointmentsViewModel.getRegionMappedProjectList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|