Skip to content

Cart Model

Source: pharmanet/lib/core/models/cart_model.dart

CartItem — @freezed

Field Type Description
product Product Full product data (not just ID)
quantity int Item count (default: 1)

The cart stores the complete Product object inline to avoid extra API calls when rendering the cart page.

Cart API (Supabase tables)

Source: pharmanet/lib/core/api/cart_api.dart

API Method Supabase Table Used
fetchCart() carts + cart_items JOIN products
addToCart(...) cart_items (upsert)
updateCartItemQuantity(...) cart_items
removeFromCart(...) cart_items
clearCart() cart_items (delete all)

Cart Provider

Source: pharmanet/lib/core/providers/cart_provider.dart

final cartProvider = NotifierProvider<CartNotifier, List<CartItem>>(CartNotifier.new);

The notifier syncs between local state and Supabase cart_items table.