arch-atlas

LocalCartItem

models/local_cart_item.dart

domain

Overview

Per-device cart line. Keyed by variantId, carries productId, title, optional thumbnail, variantTitle, mutable quantity and unitPrice. Round-trips through JSON via encodeList / decodeList for storage.

User Flow

  1. addToCart constructs a LocalCartItem and either pushes it onto the list or increments an existing entry's quantity.
  2. copyWith is used by the controller to immutably bump quantity without losing other fields.
  3. encodeList serializes the whole list to a JSON string before SharedPreferences write.

Cases & Edge Cases

  • decodeList catches any decoding error and returns []; corrupt local data is silently reset rather than crashing.
  • Quantity is marked non-final but the controller always uses copyWith — direct mutation is a footgun that bypasses _saveToStorage.
  • totalPrice is computed (no rounding) — float drift accumulates on big quantities but is reconciled when the backend cart is built.

Code References

  • lib/src/features/shared/cart/models/local_cart_item.dart:5 // LocalCartItem
  • lib/src/features/shared/cart/models/local_cart_item.dart:24 // totalPrice
  • lib/src/features/shared/cart/models/local_cart_item.dart:69 // encodeList/decodeList

API Calls

Empty — fill this in later. Open the manifest and add content here.

Notes

No backend ID field — once the user proceeds to checkout, items are 'translated' into backend line-items by variantId. Local IDs are not preserved server-side.