This method is called when we have to add an item to the cart
Example:
void addToCart(YourProductModel product) {
flutterCart.addToCart(
cartModel: CartModel(
// ... other parameters
if discount is applicable and in percentage so, you can
calculate the discount like this
var discount = (product.discountPercentage / 100) * product.price;
discount: discount,
productMeta takes Map<String, dynamic> so, you can store your complete product data in productMeta
productMeta: product.toJson()),
);
}
applyDiscount use this method when you have case where you have to apply discount
on specific product. Otherwise you can also apply discount the time of adding product into the cart.
Check addToCart example for more info.
Set isPersistenceSupportEnabled to true to turn on the cart persistence
Example:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var cart = FlutterCart();
await cart.initializeCart(isPersistenceSupportEnabled: true);
runApp(MyApp());
}
updateQuantity is used to increment/decrement the item quantity
Example:
void updateQuantity(CartModel item, int newQuantity) {
flutterCart.updateQuantity(
item.productId, item.variants, newQuantity);
}