addToCart method

  1. @override
Future<bool> addToCart(
  1. String sku,
  2. int quantity, [
  3. Map<String, dynamic>? productOption
])
override

Add item to cart.

Adds a product to the shopping cart with the specified quantity.

sku the product's SKU to add quantity the quantity to add productOption optional product options (size, color, etc.)

Returns true if item was added successfully, false otherwise.

Implementation

@override
Future<bool> addToCart(
  String sku,
  int quantity, [
  Map<String, dynamic>? productOption,
]) async {
  try {
    final result = await methodChannel.invokeMethod<bool>('addToCart', {
      'sku': sku,
      'quantity': quantity,
      'productOption': productOption,
    });
    return result ?? false;
  } catch (e) {
    _error = e.toString();
    return false;
  }
}