getPickUpLocationList method
Implementation
Future<void> getPickUpLocationList(String dealerId,
{String? search, int? page = 1}) async {
print("object $search");
BuildContext context = Get.context!;
if (page == 1 && search == null) {
Helper.progressDialog(context, "Please wait..");
}
if (search != null) {
isSearchingPickupLocation.value = true;
}
String requestTime = "";
String responseTime = "";
try {
await ApiClient(
baseUrl: ApiConstant.baseUrl,
onFetchRequestTime: (time) {
requestTime = time;
},
onFetchResponseTime: (time) {
responseTime = time;
},
screenName: "stockOrder",
)
.getPickUpLocationList(
xUserId: SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
search: search,
dealerId: dealerId,
status: 1,
page: page,
size: 10,
orderByCoordinates: true,
coordinate1: selectedDeliveryName.value == "pickup"
? currentDeliveryLocationAtPickup.latitude
: currentDeliveryLocation.latitude,
coordinate2: selectedDeliveryName.value == "pickup"
? currentDeliveryLocationAtPickup.longitude
: currentDeliveryLocation.longitude,
isPickupAvailable: selectedDeliveryName.value == "pickup" ? true : null,
isDeliveryAvailable:
selectedDeliveryName.value == "pickup" ? null : true,
)
.then((response) async {
pickUpLocation.PickupLocationModel model = response;
if (model.content != null) {
Helper.logEvent(
"RESPONSE_EVENT",
success: true,
endPoint: Api.pickUpLocationList,
responseDate: responseTime,
screenName: "stockOrder",
requestDate: requestTime,
);
if (page == 1) {
pickupLocationList.value = model;
totalPickupLocations = model.totalElements ?? 0;
pickupLocationListContent.value = model.content ?? [];
if (selectedFirstTimeSelect == "0") {
if (search == null) {
await callPickUpUpdate();
}
}
isLoadingMore.value = false;
if (page == 1 && search == null) {
Helper.close();
}
} else {
pickupLocationList.value = model;
totalPickupLocations = model.totalElements ?? 0;
pickupLocationListContent.addAll(model.content ?? []);
isLoadingMore.value = false;
}
isSearchingPickupLocation.value = false;
} else {
isSearchingPickupLocation.value = false;
if (page == 1 && search == null) {
Helper.close();
}
}
// if (model.status == "POS200") {
// } else {
// }
}).catchError((error) {
isSearchingPickupLocation.value = false;
ConditionalLogs().customLog("$error");
if (error is DioException) {
UDID.setTraceId(
error.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
);
Helper.logEvent(
"ERROR_EVENT",
failure: true,
requestDate: requestTime,
endPoint: Api.pickUpLocationList,
responseDate: DateTime.now().toString(),
screenName: "stockOrder",
error: error,
);
}
isLoadingMore.value = false;
if (page == 1 && search == null) {
Helper.close();
}
// MainController mainController = Get.put(MainController());
// mainController.showErrorPopup();
});
} catch (error, stacktrace) {
isSearchingPickupLocation.value = false;
isLoadingMore.value = false;
if (page == 1 && search == null) {
Helper.close();
}
ConditionalLogs().customLog("$stacktrace");
ConditionalLogs().customLog("$stacktrace");
if (error is DioException) {
UDID.setTraceId(
error.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
);
Helper.logEvent(
"ERROR_EVENT",
failure: true,
requestDate: requestTime,
endPoint: Api.pickUpLocationList,
responseDate: DateTime.now().toString(),
screenName: "stockOrder",
error: error,
);
}
}
}