arch-atlas

Cart Selection Controller

controllers/cart_selection_controller.dart

domain

Overview

Tracks which variantIds the user has ticked for checkout. Derived from cartControllerProvider so it auto-resets to 'all selected' whenever the cart list itself changes.

User Flow

  1. build() watches cartControllerProvider and returns cartItems.map(variantId).toSet().
  2. toggleItem flips one entry; selectAll / deselectAll bulk update.
  3. CartScreen reads this set to decide which items show a tick + which contribute to the running total.

Cases & Edge Cases

  • Adding a new item to the cart auto-selects it (build re-runs and the new variantId enters the set).
  • Removing an item triggers build → the absent variantId silently drops out of the selection.
  • Selection is in-memory only; it is not persisted across app kills.

Code References

  • lib/src/features/shared/cart/controllers/cart_selection_controller.dart:5 // CartSelectionController
  • lib/src/features/shared/cart/controllers/cart_selection_controller.dart:9 // auto-select on cart change

API Calls

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

Notes

By rebuilding from the cart, selection 'recovers' from edits without the screen having to call selectAll manually — but a screen that 'unticked everything' loses that state on the next cart edit.