getSearchHospitalList method
Future
getSearchHospitalList({
- dynamic hospitalName,
- dynamic pincode,
- dynamic city,
- dynamic stateName,
- dynamic policyId,
- required dynamic context,
- dynamic currentPage,
- bool ispagination = false,
Implementation
Future getSearchHospitalList({
hospitalName,
pincode,
city,
stateName,
policyId,
required context,
currentPage,
bool ispagination = false,
}) async {
try {
final response = await apiRequest(
'GET',
'${APP_URL}hospital-list?policy_id=$policyId&state=${stateName ?? ''}&city=${city ?? ''}&hospital_name=${hospitalName ?? ''}&page=${currentPage ?? '1'}&pincode=${pincode ?? ''}',
null,
);
Get.back(); // Close the loader
if (response['success'] == true) {
WholeHospitalData = response['data'];
if (ispagination) {
// Append new data to existing list for infinite scroll
HospitalList = [...HospitalList, ...response['data']['data']];
} else {
// Replace list for initial load or new search
HospitalList = response['data']['data'];
searchHospitalList = response['data']['data']; // Reset search list
Get.to(
SearchHospitalList(
pincode: pincode ?? '',
hospitalName: hospitalName ?? '',
city: city ?? '',
stateName: stateName ?? '',
),
);
}
return response['data']; // Return data for potential further processing
} else {
Validator().errorMessage(
context: context,
message: response['message'] ?? 'Failed to load hospital list',
);
return null;
}
} catch (e) {
Get.back(); // Ensure loader is closed on error
Validator().errorMessage(
context: context,
message: 'An error occurred while fetching hospital list',
);
return null;
}
}