Gerencie e persista dados de carrinho de compras no seu aplicativo Flutter com este pacote abrangente. Simplifique o armazenamento local e melhore a experiência de compra para seus usuários.
Orientação gerada a partir de informações públicas. Apenas para referência.
Um pacote Flutter que permite gerenciamento contínuo e armazenamento persistente de dados do carrinho de compras após reinícios do aplicativo. Simplifica o manuseio de dados locais ao salvar automaticamente o conteúdo do carrinho no armazenamento do dispositivo, garantindo que os usuários mantenham suas seleções mesmo após fechar o app. Ideal para aplicações de comércio eletrônico, melhora a experiência do usuário ao preservar a integridade do carrinho. O pacote suporta múltiplas plataformas, incluindo Android, iOS, macOS, Windows e Linux, tornando-o versátil para desenvolvimento multiplataforma.
Casos de uso
Aplicativos de comércio eletrônico com carrinhos de usuário
Experiências de compras offline
Seleção persistente de produtos
Sincronização de carrinho entre dispositivos
Continuidade da sessão do usuário
Principais recursos
Persistência local automática
Compatibilidade multiplataforma
API simples para operações de carrinho
Atualizações em tempo real do carrinho
Suporte para dados complexos de itens
Indicado para
Aplicativos de comércio eletrônico móvel
Aplicativos de compras
Aplicativos que exigem dados offline
Desenvolvedores procurando gerenciamento fácil de carrinho
Projetos direcionados para múltiplas plataformas
Considerações
Requer tratamento adequado de erros para falhas de armazenamento
Pode ser necessário personalizar para grandes conjuntos de dados do carrinho
Depende da inicialização correta
Não adequado para sincronização de carrinho baseada em nuvem
Limitado apenas ao armazenamento local
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
Persistent Shopping Cart
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
Features
Initialization: Easily initialize the shopping cart using init() method.
Add to Cart: Add products to the cart with the addToCart method.
Remove from Cart: Remove products from the cart using the removeFromCart method.
Increment/Decrement Quantity: Adjust the quantity of items in the cart with the incrementCartItemQuantity and decrementCartItemQuantity methods.
Calculate Total Price: Get the total price of items in the cart using the calculateTotalPrice method.
Get Cart Item Count: Retrieve the total number of items in the cart with the getCartItemCount method.
Clear Cart: Remove all items from the cart using the clearCart method.
Show Cart Items: Display the cart items using the showCartItems method, providing flexible builders for customizing how the cart is displayed (e.g., ListView, GridView).
Show Cart Item Count Widget: Show a widget displaying the current cart item count using the showCartItemCountWidget method.
Show Total Amount Widget: Display a widget showing the total amount of items in the cart with the showTotalAmountWidget method.
Show and Update Cart Item Widget: Show a widget that dynamically updates based on whether a product is in the cart or not, using the showAndUpdateCartItemWidget method.
Retrieve Cart Data and Total Price: Use getCartData method in the PersistentShoppingCart class to get a list of cart items and the total price.
Start using the shopping cart functionality in your application!
Example Usage
// Add product to the cartawaitPersistentShoppingCart().addToCart(PersistentShoppingCartItem());
// Remove product from the cartawaitPersistentShoppingCart().removeFromCart(productId);
// Increment product quantity in the cartawaitPersistentShoppingCart().incrementCartItemQuantity(productId);
// Decrement product quantity in the cartawaitPersistentShoppingCart().decrementCartItemQuantity(productId);
// Get total price of items in the cartdouble totalPrice = PersistentShoppingCart().calculateTotalPrice();
// Get total number of items in the cartint itemCount = PersistentShoppingCart().getCartItemCount();
// Clear the cartPersistentShoppingCart().clearCart();
// Retrieve cart data and total priceMap<String, dynamic> cartData = PersistentShoppingCart().getCartData();
List<PersistentShoppingCartItem> cartItems = cartData['cartItems'];
double totalPriceFromData = cartData['totalPrice'];
Widgets
Show Cart Items
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 cartif(cartItems.isEmpty){
returnEmptyCartMsgWidget();
}
// Define your custom widget for displaying cart itemsreturnListView.builder(
itemCount: cartItems.length,
itemBuilder: (context, index) {
final item = cartItems[index];
returnListTile(
title: Text(item.name), // Replace with your cart item widget
subtitle: Text('Quantity: ${item.quantity}'),
);
},
);
},
);
Show Cart Item Count Widget
PersistentShoppingCart().showCartItemCountWidget(
cartItemCountWidgetBuilder: (int itemCount) {
// Your custom widget displaying the cart item count
},
);
Show Total Amount Widget
PersistentShoppingCart().showTotalAmountWidget(
cartTotalAmountWidgetBuilder: (double totalAmount) {
// Your custom widget displaying the total amount
},
);