removeLineItemsFromCart method

Future<Cart> removeLineItemsFromCart({
  1. required String cartId,
  2. required List<String> lineIds,
  3. bool reverse = false,
})

remove line item from cart

If the reverse is set to true, the line items in the cart will be in reverse order.

Implementation

Future<Cart> removeLineItemsFromCart({
  required String cartId,
  required List<String> lineIds,
  bool reverse = false,
}) async {
  final MutationOptions removeLineItem = MutationOptions(
    document: gql(removeLineItemFromCartMutation),
    variables: {
      'cartId': cartId,
      'lineIds': lineIds,
      'country': ShopifyLocalization.countryCode,
      'reverse': reverse
    },
  );
  QueryResult result = await _graphQLClient!.mutate(removeLineItem);
  checkForError(result, key: 'cartLinesRemove', errorKey: 'userErrors');

  return Cart.fromJson(
      ((result.data!['cartLinesRemove'] ?? const {})['cart'] ?? const {}));
}