패키지, 저장소 및 앱 카테고리 검색

persistent_shopping_cart 표지
패키지 상세v0.0.8

persistent_shopping_cart

이 포괄적인 패키지를 사용하여 Flutter 앱에서 쇼핑카트 데이터를 쉽게 관리하고 지속적으로 저장하세요. 로컬 스토리지의 단순화와 사용자에게 더 나은 쇼핑 경험 제공

AndroidiOSmacOSWindowsLinux
30일 다운로드
59
좋아요
270
Pub 점수
160

패키지 설치

flutter pub add persistent_shopping_cart

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

앱 재시작 후에도 쇼핑카트 데이터를 원활하게 관리하고 지속적으로 저장할 수 있도록 해주는 플러터 패키지입니다. 카트 내용을 자동으로 기기 저장소에 저장함으로써 로컬 데이터 처리를 간편하게 만들어주며, 앱을 종료한 후에도 사용자가 선택한 항목을 유지할 수 있도록 보장합니다. 전자상거래 애플리케이션에 이상적이며, 카트의 무결성을 유지함으로써 사용자 경험을 향상시킵니다. 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.