fetchProducts method
void
fetchProducts(
- BuildContext context,
- String? consumerApiKey,
- String? merchantId,
- String? customerId,
Implementation
void fetchProducts(BuildContext context, String? consumerApiKey,
String? merchantId, String? customerId) async {
items.clear();
try {
isLoading(true);
var request = {
'api_key': await Constants.apiKey(),
'merchant_id': merchantId ?? Storage.getValue(Constants.merchantID),
'customer_id': customerId ?? Storage.getValue(Constants.customerID)
};
var response = await DioClient().request(
context: context,
api: '/customer/products/featured',
method: Method.POST,
params: request);
GetProductsResponse getProductsResponse =
GetProductsResponse.fromJson(response);
if (getProductsResponse.status == Strings.success) {
items.addAll(getProductsResponse.data!.obs);
} else {
isError(true);
errorMessage.value = response['message'].toString().toTitleCase();
return Utils.showSnackbar(context, Strings.error,
response['message'].toString().toTitleCase(), AppColors.red);
}
} finally {
isLoading(false);
isError(false);
}
update();
}