|
| 1 | +# FlutterCart: Your Mobile Shopping Companion |
| 2 | + |
| 3 | +FlutterCart is a versatile Flutter package that brings robust shopping cart capabilities to your mobile application. It leverages Hive for local storage, ensuring your shopping cart data is retained across different app sessions. |
| 4 | + |
| 5 | +## Key Features |
| 6 | + |
| 7 | +- **Initialization**: Kickstart the shopping cart with the `init()` method. |
| 8 | +- **Cart Operations**: Include items to the cart with `addToCart`, and remove them using `removeFromCart`. |
| 9 | +- **Quantity Control**: Fine-tune the item quantity with `incrementCartItemQuantity` and `decrementCartItemQuantity`. |
| 10 | +- **Total Price Calculation**: Fetch the total price of cart items using `calculateTotalPrice`. |
| 11 | +- **Item Count**: Retrieve the total number of items with `getCartItemCount`. |
| 12 | +- **Cart Clearance**: Wipe out all items from the cart with `clearCart`. |
| 13 | +- **Cart Item Display**: Visualize the cart items with `showCartItems`, offering customizable widgets for individual cart items and an empty cart message. |
| 14 | +- **Item Count Widget**: Display a widget featuring the current cart item count using `showCartItemCountWidget`. |
| 15 | +- **Total Amount Widget**: Showcase a widget revealing the total amount of items in the cart with `showTotalAmountWidget`. |
| 16 | +- **Dynamic Cart Item Widget**: Illustrate a widget that updates based on whether a product is in the cart or not, using `showAndUpdateCartItemWidget`. |
| 17 | +- **Cart Data Retrieval**: Use `getCartData` in the `FlutterCart` class to fetch a list of cart items and the total price. |
| 18 | + |
| 19 | +## How to Get Started |
| 20 | + |
| 21 | +1. Incorporate the package in your Dart file: |
| 22 | + |
| 23 | +```dart |
| 24 | +import 'package:flutter_cart/flutter_cart.dart'; |
| 25 | +``` |
| 26 | + |
| 27 | +2. Set the ball rolling by initializing the cart: |
| 28 | + |
| 29 | +```dart |
| 30 | +await FlutterCart().init(); |
| 31 | +``` |
| 32 | + |
| 33 | +3. You're all set to harness the shopping cart features in your application! |
| 34 | + |
| 35 | +## Usage Examples |
| 36 | + |
| 37 | +```dart |
| 38 | +// Add products to the cart |
| 39 | +await FlutterCart().addToCart(FlutterCartItem()); |
| 40 | +
|
| 41 | +// Eliminate a product from the cart |
| 42 | +await FlutterCart().removeFromCart(productId); |
| 43 | +
|
| 44 | +// Increase the product quantity in the cart |
| 45 | +await FlutterCart().incrementCartItemQuantity(productId); |
| 46 | +
|
| 47 | +// Reduce the product quantity in the cart |
| 48 | +await FlutterCart().decrementCartItemQuantity(productId); |
| 49 | +
|
| 50 | +// Fetch the total price of cart items |
| 51 | +double totalPrice = FlutterCart().calculateTotalPrice(); |
| 52 | +
|
| 53 | +// Get the total quantity of cart items |
| 54 | +int itemCount = FlutterCart().getCartItemCount(); |
| 55 | +
|
| 56 | +// Empty the cart |
| 57 | +FlutterCart().clearCart(); |
| 58 | +
|
| 59 | +// Fetch cart data and total price |
| 60 | +Map<String, dynamic> cartData = FlutterCart().getCartData(); |
| 61 | +List<FlutterCartItem> cartItems = cartData['cartItems']; |
| 62 | +double totalPriceFromData = cartData['totalPrice']; |
| 63 | +``` |
| 64 | + |
| 65 | +## Widgets |
| 66 | + |
| 67 | +### Cart Item Display |
| 68 | + |
| 69 | +```dart |
| 70 | +FlutterCart().showCartItems( |
| 71 | + cartTileWidget: ({required FlutterCartItem data}) { |
| 72 | + // Your personalized cart item widget |
| 73 | + }, |
| 74 | + showEmptyCartMsgWidget: YourEmptyCartMessageWidget(), |
| 75 | +); |
| 76 | +``` |
| 77 | + |
| 78 | +### Cart Item Count Widget |
| 79 | + |
| 80 | +```dart |
| 81 | +FlutterCart().showCartItemCountWidget( |
| 82 | + cartItemCountWidgetBuilder: (int itemCount) { |
| 83 | + // Your personalized widget displaying the cart item count |
| 84 | + }, |
| 85 | +); |
| 86 | +``` |
| 87 | + |
| 88 | +### Total Amount Widget |
| 89 | + |
| 90 | +```dart |
| 91 | +FlutterCart().showTotalAmountWidget( |
| 92 | + cartTotalAmountWidgetBuilder: (double totalAmount) { |
| 93 | + // Your personalized widget displaying the total amount |
| 94 | + }, |
| 95 | +); |
| 96 | +``` |
| 97 | + |
| 98 | +### Dynamic Cart Item Widget |
| 99 | + |
| 100 | +```dart |
| 101 | +FlutterCart().showAndUpdateCartItemWidget( |
| 102 | + inCartWidget: YourInCartWidget(), |
| 103 | + notInCartWidget: YourNotInCartWidget(), |
| 104 | + product: yourProduct, |
| 105 | +); |
| 106 | +``` |
| 107 | + |
| 108 | +"Simplify your mobile shopping experience with FlutterCart!" |
0 commit comments