v0.0.9flutter_cart
A flutter package for the cart management. This package helps you to perform basic cart operation like (Add to cart, Remove from cart, Get total count) etc.
Flutter package for the cart management
{"sdk":"flutter"}^2.4.6^2.4.1^2.2.2{"sdk":"flutter"}^2.4.8^6.7.1English project snapshot. Visit GitHub for the latest content.
logo
pub package
Empower your Flutter app with seamless cart management using this powerful package. This comprehensive Flutter package offers a wide range of cart management features that simplify the process of adding, removing, and updating items in your app's cart. With its easy-to-use functionality, managing your app's cart has never been easier.
sample
To use this plugin, add flutter_cart as a dependency in your pubspec.yaml file.
dependencies:
flutter:
sdk: flutter
flutter_cart:
This package is using shared_preferences for persisting cart items.
first, create an instance of flutter_cart package.
// Set [isPersistenceSupportEnabled] to true to turn on the cart persistence
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var cart = FlutterCart();
await cart.initializeCart(isPersistenceSupportEnabled: true);
runApp(MyApp());
}
// This method is called when we have to add an item to the cart
// Example:
void addToCart(YourProductModel product) {
flutterCart.addToCart(
cartModel: CartModel(
// ... other parameters
if [discount] is applicable and in percentage so, you can
calculate the discount like this
var discount = (product.discountPercentage / 100) * product.price;
discount: discount,
[productMeta] takes Map<String, dynamic> so, you can store your complete product data in productMeta
productMeta: product.toJson()),
);
}
// [updateQuantity] is used to increment/decrement the item quantity
// Example:
void updateQuantity(CartModel item, int newQuantity) {
flutterCart.updateQuantity(
item.productId, item.variants, newQuantity);
}
// [removeItem] is used for removing the specific item from the cart
// Example:
void removeItemFromCart(CartModel item) {
flutterCart.removeItem(item.productId, item.variants);
}
void clearCart() {
flutterCart.clearCart();
}
List<CartModel> get getCartItems => flutterCart.cartItemsList;
int get getCartCount => flutterCart.cartLength;
double get getTotalAmount => flutterCart.total;
double get subtotal => flutterCart.subtotal;