パッケージ、リポジトリ、アプリカテゴリを検索

persistent_shopping_cart のカバー
パッケージ詳細v0.0.8

persistent_shopping_cart

この包括的なパッケージを使用して、Flutterアプリでショッピングカートデータを簡単に管理および永続化できます。ローカルストレージを簡素化し、ユーザーのショッピング体験を向上させます。

AndroidiOSmacOSWindowsLinux
30日間ダウンロード
59
いいね数
270
Pub ポイント
160

パッケージをインストール

flutter pub add persistent_shopping_cart

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Flutterパッケージで、アプリの再起動後にショッピングカートデータをシームレスに管理し、永続的に保存できます。自動的にカートの内容をデバイスストレージに保存することで、ローカルデータ処理を簡素化し、アプリを閉じた後もユーザーが選択した内容を保持できるようにします。eコマースアプリに最適で、カートの整合性を維持することでユーザーエクスペリエンスを向上させます。Android、iOS、macOS、Windows、Linuxなど複数のプラットフォームをサポートしており、クロスプラットフォーム開発に非常に柔軟に対応しています。

用途

  • ユーザー カート付きの e コマース アプリ
  • オフラインショッピング体験
  • 永続的な製品選択
  • デバイス間のカート同期
  • ユーザーのセッション継続性

主な機能

  • 自動ローカル永続化
  • クロスプラットフォーム互換性
  • カート操作のためのシンプルな 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 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。