FlutterCart is a versatile Flutter package that brings robust shopping cart capabilities to your mobile application. It leverages Hive for local storage, ensuring your shopping cart data is retained across different app sessions.
- Initialization: Kickstart the shopping cart with the
init()
method. - Cart Operations: Include items to the cart with
addToCart
, and remove them usingremoveFromCart
. - Quantity Control: Fine-tune the item quantity with
incrementCartItemQuantity
anddecrementCartItemQuantity
. - Total Price Calculation: Fetch the total price of cart items using
calculateTotalPrice
. - Item Count: Retrieve the total number of items with
getCartItemCount
. - Cart Clearance: Wipe out all items from the cart with
clearCart
. - Cart Item Display: Visualize the cart items with
showCartItems
, offering customizable widgets for individual cart items and an empty cart message. - Item Count Widget: Display a widget featuring the current cart item count using
showCartItemCountWidget
. - Total Amount Widget: Showcase a widget revealing the total amount of items in the cart with
showTotalAmountWidget
. - Dynamic Cart Item Widget: Illustrate a widget that updates based on whether a product is in the cart or not, using
showAndUpdateCartItemWidget
. - Cart Data Retrieval: Use
getCartData
in theFlutterCart
class to fetch a list of cart items and the total price.
- Incorporate the package in your Dart file:
import 'package:flutter_cart/flutter_cart.dart';
- Set the ball rolling by initializing the cart:
await FlutterCart().init();
- You're all set to harness the shopping cart features in your application!
// Add products to the cart
await FlutterCart().addToCart(FlutterCartItem());
// Eliminate a product from the cart
await FlutterCart().removeFromCart(productId);
// Increase the product quantity in the cart
await FlutterCart().incrementCartItemQuantity(productId);
// Reduce the product quantity in the cart
await FlutterCart().decrementCartItemQuantity(productId);
// Fetch the total price of cart items
double totalPrice = FlutterCart().calculateTotalPrice();
// Get the total quantity of cart items
int itemCount = FlutterCart().getCartItemCount();
// Empty the cart
FlutterCart().clearCart();
// Fetch cart data and total price
Map<String, dynamic> cartData = FlutterCart().getCartData();
List<FlutterCartItem> cartItems = cartData['cartItems'];
double totalPriceFromData = cartData['totalPrice'];
FlutterCart().showCartItems(
cartTileWidget: ({required FlutterCartItem data}) {
// Your personalized cart item widget
},
showEmptyCartMsgWidget: YourEmptyCartMessageWidget(),
);
FlutterCart().showCartItemCountWidget(
cartItemCountWidgetBuilder: (int itemCount) {
// Your personalized widget displaying the cart item count
},
);
FlutterCart().showTotalAmountWidget(
cartTotalAmountWidgetBuilder: (double totalAmount) {
// Your personalized widget displaying the total amount
},
);
FlutterCart().showAndUpdateCartItemWidget(
inCartWidget: YourInCartWidget(),
notInCartWidget: YourNotInCartWidget(),
product: yourProduct,
);
"Simplify your mobile shopping experience with FlutterCart!"