getListingList function
Implementation
Future<ListingListModel?> getListingList({bool showLoader = false, bool isFavourite = false, bool isSaveFilter = false, bool isFromReset = false}) async {
if (showLoader) appStore.setLoading(true);
try {
// if (isFromReset == true) {
// isSaveFilter = false;
// }
String filter = (isSaveFilter && !isFromReset) ? "&apply_filter=true" : '';
String sortListingKey = await getStringAsync(SORT_LIST_KEY);
String sortListingValue = await getStringAsync(SORT_LIST_VALUE);
String sortKeyValuePair = (sortListingKey.isNotEmpty) ? "&$sortListingKey=$sortListingValue" : "";
String musicTypeId = ((appStore.selectedMusicId != -1) && (appStore.headerIndex != 2 && appStore.headerIndex != -1)) ? "&music_type_id=${appStore.selectedMusicId}" : '';
String userId = (appStore.userId != null && appStore.userId != 0) ? "?user_id=${appStore.userId}" : '?user_id=';
String type = isFavourite ? '&is_favourite=1' : '';
String latlang = (appStore.isLocationPermissionGranted && (appStore.headerIndex == 2)) ? "&latitude=${appStore.latitude}2&longitude=${appStore.longitude}" : "";
String perPage = "&per_page=All";
//reminder add latlng in API
ListingResponse res = ListingResponse.fromMap(await (handleResponse(await buildHttpResponse("${APIEndPoint.listingList}$userId$type$latlang$musicTypeId$sortKeyValuePair$filter$perPage", method: HttpMethod.GET))));
cachedListingListModel = await res.data;
appStore.setLoading(false);
return await res.data;
} catch (e) {
appStore.setLoading(false);
throw errorSomethingWentWrong;
}
}