FlutterCart class

Constructors

FlutterCart()
factory

Properties

cartItemsList List<CartModel>
no setter
cartLength int
no setter
discount double
no setter
hashCode int
The hash code for this object.
no setterinherited
persistenceCartItemsList List<CartModel>?
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
subtotal double
This method is called when we have to get the Total amount
no setter
total double
no setter

Methods

addToCart({required CartModel cartModel}) → void
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(String productId, List<ProductVariant> variants, double discount) → void
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.
clearCart() → void
clearCart will clear the complete cart, including both in-memory and persistent cart data.
getPersistenceSupportStatus() bool
getPersistenceSupportStatus use this method to check the persistence storage enable/disable status
getProductIndex(String productId, List<ProductVariant> variants) int
getProductIndex will return the specific item index
getSpecificProduct(String productId, List<ProductVariant> variants) CartModel?
getSpecificProduct will return the specific item from cart
initializeCart({bool isPersistenceSupportEnabled = false}) Future<void>
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()); }
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeItem(String productId, List<ProductVariant> variants) → void
removeItem is used for removing the specific item from the cart Example: void removeItemFromCart(CartModel item) {
toString() String
A string representation of this object.
inherited
updateQuantity(String productId, List<ProductVariant> variants, int newQuantity) → void
updateQuantity is used to increment/decrement the item quantity Example: void updateQuantity(CartModel item, int newQuantity) { flutterCart.updateQuantity( item.productId, item.variants, newQuantity); }

Operators

operator ==(Object other) bool
The equality operator.
inherited