getMyCartItemByKey method

Future<WooCartItem> getMyCartItemByKey(
  1. String key
)

Returns a WooCartItem, with the specified key.

Implementation

Future<WooCartItem> getMyCartItemByKey(String key) async {
  await getAuthTokenFromDb();
  _urlHeader['Authorization'] = 'Bearer ' + _authToken!;
  WooCartItem cartItem;
  final response = await http.get(
      Uri.parse(this.baseUrl + URL_STORE_API_PATH + 'cart/items/' + key),
      headers: _urlHeader);
  _printToLog('response gotten : ' + response.toString());
  if (response.statusCode >= 200 && response.statusCode < 300) {
    final jsonStr = json.decode(response.body);
    cartItem = WooCartItem.fromJson(jsonStr);
    return cartItem;
  } else {
    _printToLog('error : ' + response.body);
    WooCommerceError err =
        WooCommerceError.fromJson(json.decode(response.body));
    throw err;
  }
}