fetchProducts method

Future<void> fetchProducts(
  1. BuildContext context,
  2. String? merchantID
)

Implementation

Future<void> fetchProducts(BuildContext context, String? merchantID) async {
  tempItems.clear();
  items.clear();
  try {
    isLoading(true);
    var request = {
      'api_key': await Constants.apiKey(),
      'merchant_id': merchantID ?? Storage.getValue(Constants.merchantID)
    };
    var response = await DioClient().request(
        context: context,
        api: '/merchant/products/get',
        method: Method.POST,
        params: request);

    GetProductsResponse getProductsResponse =
        GetProductsResponse.fromJson(response);
    if (getProductsResponse.status == Strings.success) {
      tempItems.addAll(getProductsResponse.data!.obs);
      items.addAll(tempItems);
      totalResults = items.length.obs;
    } else {
      isError(true);
      errorMessage.value = response['message'].toString().toTitleCase();
      return Utils.showSnackbar(context, Strings.error,
          response['message'].toString().toTitleCase(), AppColors.red);
    }
  } finally {
    isLoading(true);
  }
  update();
}