v0.0.8persistent_shopping_cart
使用此完整的套件,輕鬆管理並持久化您的 Flutter 應用中的購物車資料。簡化本機儲存,提升使用者的購物體驗。
272喜歡 56近 30 天下載160Pub 分數
AndroidiOSmacOSWindowsLinux
axiftaj/persistent_shopping_cart open-source repository details.
{"sdk":"flutter"}^2.2.3^2.1.5^1.1.0^2.4.14^2.0.1{"sdk":"flutter"}^5.0.0以下為英文專案原文快照,最新內容請造訪 GitHub。
Persistent Shopping Cart is a Flutter package that provides a simple and persistent shopping cart functionality for your mobile application. It uses Hive for local storage, making the cart data persist across app sessions.
Demo Preview
init() method.addToCart method.removeFromCart method.incrementCartItemQuantity and decrementCartItemQuantity methods.calculateTotalPrice method.getCartItemCount method.clearCart method.showCartItems method, providing flexible builders for customizing how the cart is displayed (e.g., ListView, GridView).showCartItemCountWidget method.showTotalAmountWidget method.showAndUpdateCartItemWidget method.getCartData method in the PersistentShoppingCart class to get a list of cart items and the total price.import 'package:persistent_shopping_cart/persistent_shopping_cart.dart';
init method:await PersistentShoppingCart().init();
// Add product to the cart
await PersistentShoppingCart().addToCart(PersistentShoppingCartItem());
// Remove product from the cart
await PersistentShoppingCart().removeFromCart(productId);
// Increment product quantity in the cart
await PersistentShoppingCart().incrementCartItemQuantity(productId);
// Decrement product quantity in the cart
await PersistentShoppingCart().decrementCartItemQuantity(productId);
// Get total price of items in the cart
double totalPrice = PersistentShoppingCart().calculateTotalPrice();
// Get total number of items in the cart
int itemCount = PersistentShoppingCart().getCartItemCount();
// Clear the cart
PersistentShoppingCart().clearCart();
// Retrieve cart data and total price
Map<String, dynamic> cartData = PersistentShoppingCart().getCartData();
List<PersistentShoppingCartItem> cartItems = cartData['cartItems'];
double totalPriceFromData = cartData['totalPrice'];
The showCartItems method now provides flexibility to define how cart items are displayed (e.g., ListView, GridView) using a builder function.
PersistentShoppingCart().showCartItems(
cartItemsBuilder: (BuildContext context, List<PersistentShoppingCartItem> cartItems) {
// no item added to cart
if(cartItems.isEmpty){
return EmptyCartMsgWidget();
}
// Define your custom widget for displaying cart items
return ListView.builder(
itemCount: cartItems.length,
itemBuilder: (context, index) {
final item = cartItems[index];
return ListTile(
title: Text(item.name), // Replace with your cart item widget
subtitle: Text('Quantity: ${item.quantity}'),
);
},
);
},
);
PersistentShoppingCart().showCartItemCountWidget(
cartItemCountWidgetBuilder: (int itemCount) {
// Your custom widget displaying the cart item count
},
);
PersistentShoppingCart().showTotalAmountWidget(
cartTotalAmountWidgetBuilder: (double totalAmount) {
// Your custom widget displaying the total amount
},
);
PersistentShoppingCart().showAndUpdateCartItemWidget(
inCartWidget: YourInCartWidget(),
notInCartWidget: YourNotInCartWidget(),
product: yourProduct,
);