addToCart method Null safety

dynamic addToCart(
  1. {@required dynamic productId,
  2. @required dynamic unitPrice,
  3. String? productName,
  4. int quantity = 1,
  5. dynamic uniqueCheck,
  6. dynamic productDetailsObject}
)

This method is called when we have to add productTemp into cart

Implementation

addToCart(
    {@required dynamic productId,
    @required dynamic unitPrice,
    String? productName,
    int quantity = 1,
    dynamic uniqueCheck,
    dynamic productDetailsObject}) {
  _cartItem = new CartItem();
  _setProductValues(productId, unitPrice, productName, quantity, uniqueCheck,
      productDetailsObject);
  if (_cartItemList.isEmpty) {
    _cartItem.subTotal =
        double.parse((quantity * unitPrice).toStringAsFixed(2));
    _uuid.add(_cartItem.uuid);
    _cartItemList.add(_cartItem);

    message = CartResponseWrapper(true, _successMessage, _cartItemList);
    return message;
  } else {
    _cartItemList.forEach((x) {
      if (x.productId == productId) {
        /// If item [UniqueCheck] is not null then we update the item in cart
        if (uniqueCheck != null) {
          if (x.uniqueCheck == uniqueCheck) {
            _filterItemFound = true;
            _updateProductDetails(x, quantity, unitPrice);
            /* message = {
              "status": true,
              "message": _updateMessage,
              "data": _cartItemList,
              "length": _cartItemList.length
            }; */
            message =
                CartResponseWrapper(true, _updateMessage, _cartItemList);
          }
        }

        /// if uniqueCheck is null then we update the [product] in our cart in against of [PRODUCT ID]
        else {
          _filterItemFound = true;
          _updateProductDetails(x, quantity, unitPrice);
          message = CartResponseWrapper(true, _successMessage, _cartItemList);
        }
      }
    });

    /// if _filterItemFound is [false] then we directly add the product in our cart
    if (!_filterItemFound) {
      _uuid.add(_cartItem.uuid);
      _updateProductDetails(_cartItem, quantity, unitPrice);
      _cartItemList.add(_cartItem);
      message = CartResponseWrapper(true, _successMessage, _cartItemList);
    }
    _filterItemFound = false;
    return message;
  }
}