搜尋套件、儲存庫與 APP 分類

persistent_shopping_cart 封面
套件詳情v0.0.8

persistent_shopping_cart

使用此完整的套件,輕鬆管理並持久化您的 Flutter 應用中的購物車資料。簡化本機儲存,提升使用者的購物體驗。

AndroidiOSmacOSWindowsLinux
近 30 天下載
59
喜歡數
270
Pub 分數
160

安裝套件

flutter pub add persistent_shopping_cart

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,可實現購物車資料在應用重啟後的無縫管理與持久化儲存。它透過自動將購物車內容儲存至裝置儲存空間,簡化本地資料處理,確保使用者在關閉應用後仍能保留其選擇。適用於電商應用,透過維持購物車完整性來提升使用者體驗。該套件支援 Android、iOS、macOS、Windows 及 Linux 多個平台,適用於跨平台開發。

適用情境

  • 帶有使用者購物車的電子商務應用
  • 離線購物體驗
  • 持久的產品選擇
  • 跨裝置購物車同步
  • 使用者會話連續性

主要特色

  • 自動本地持久化
  • 跨平台相容性
  • 購物車操作的簡單 API
  • 即時購物車更新
  • 對複雜項目數據的支持

適合對象

  • 移動電子商務應用
  • 購物應用
  • 需要離線資料的應用程式
  • 尋求簡易購物車管理的開發者
  • 針對多個平台的專案

使用建議

  • 需要對儲存失敗情況進行適當的錯誤處理
  • 可能需要為大型購物車數據集進行客製化
  • 依賴於正確的初始化
  • 不適用於基於雲端的購物車同步
  • 僅限本機儲存

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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

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.

Getting Started

  1. Import the package in your Dart file:
import 'package:persistent_shopping_cart/persistent_shopping_cart.dart';
  1. Initialize the cart by calling the init method:
await PersistentShoppingCart().init();
  1. Start using the shopping cart functionality in your application!

Example Usage

// 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'];

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 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}'),
        );
      },
    );
  },
);
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
  },
);
Show and Update Cart Item Widget
PersistentShoppingCart().showAndUpdateCartItemWidget(
  inCartWidget: YourInCartWidget(),
  notInCartWidget: YourNotInCartWidget(),
  product: yourProduct,
);

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。