Product Details Controller (customer)
product_details/controllers/product_details_controller.dart
Overview
Customer-side controller for ProductDetailScreen. Holds the Product, currently selected options + resolved variant, quantity, isFavorite. _resolveVariant matches the selected options against product.variants and clears the variant when none match.
User Flow
- setFromProduct seeds the state with the Product passed via route extra, auto-selecting the first value of each option.
- loadProduct(id) is the fallback path when the user deep-links without an extra — calls MarketplaceService.getProductById.
- selectOption mutates selectedOptions and re-resolves the variant.
- toggleFavorite mirrors into marketplaceControllerProvider so the parent list stays in sync.
Cases & Edge Cases
- If no variant matches the current option combination, selectedVariant is cleared — the Add-to-cart button must disable.
- Quantity has a floor of 1; UI 'minus' button hides below that.
- isFavorite is local-only in this controller — the wishlist service is what persists it.
Code References
- lib/src/features/shared/product_details/controllers/product_details_controller.dart:5 // ProductDetailsState
- lib/src/features/shared/product_details/controllers/product_details_controller.dart:50 // ProductDetailsController
- lib/src/features/shared/product_details/controllers/product_details_controller.dart:78 // loadProduct
- lib/src/features/shared/product_details/controllers/product_details_controller.dart:115 // _resolveVariant
API Calls
Empty — fill this in later. Open the manifest and add content here.
Notes
copyWith uses a `clearVariant` bool to explicitly null selectedVariant — copyWith's normal ?? pattern can't express 'set to null' otherwise.