Giter Site home page Giter Site logo

technicalwajahat / persistent_shopping_cart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from axiftaj/persistent_shopping_cart

0.0 0.0 0.0 343 KB

Shopping Cart | Flutter

License: MIT License

Ruby 3.17% C++ 26.12% C 1.61% Objective-C 0.04% Kotlin 0.17% Dart 42.51% Swift 2.20% HTML 2.14% CMake 22.05%
android dart flutter ios

persistent_shopping_cart's Introduction

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 customizable widgets for each cart item and an empty cart message.
  • 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

PersistentShoppingCart().showCartItems(
  cartTileWidget: ({required PersistentShoppingCartItem data}) {
    // Your custom cart item widget
  },
  showEmptyCartMsgWidget: YourEmptyCartMessageWidget(),
);

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,
);

persistent_shopping_cart's People

Contributors

axiftaj avatar mudasirhussain72 avatar codersangam avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.