arch-atlas

Marketplace Controller + State

controllers/marketplace_controller.dart · Notifier<ProductListState>

domain

Overview

Notifier owning the entire paged + filtered list. ProductListState carries loading flags, products, pagination cursor (offset, hasMore), every filter dimension, and the available-filter set computed from page 0.

User Flow

  1. build() schedules a Future.microtask(refresh) so the initial fetch fires on first watch.
  2. _fetchProducts respects offset and limit=20; the response is concatenated with previous pages.
  3. Sort orders 'price_asc' / 'price_desc' are applied client-side; everything else is server-side (passed as `order=` param).
  4. Available filters (Category, Colors, Size) are extracted from page 0 results via _extractFilters and cached.
  5. toggleCategory / toggleTag / toggleVariantOption flip an item in the corresponding list, then refresh.

Cases & Edge Cases

  • Medusa's variants[options][value] only accepts a single value — the controller sends the first selected option to the API and filters the rest client-side.
  • Filter-error auto-recovery: if a filtered fetch throws and any filter is active, all filters reset, warningMessage is set, and refresh fires unfiltered.
  • copyWith does not allow clearing warningMessage; clearWarning rebuilds the state explicitly with warningMessage: null.
  • Local price sort is applied on top of paged results — the order across page boundaries is unstable when more items load.
  • toggleVariantOption can't enforce per-group single-select (Color vs Size) without group knowledge — the UI must pre-process to send 'one Color + one Size'.

Code References

  • lib/src/features/shared/marketplace/controllers/marketplace_controller.dart:13 // ProductListState
  • lib/src/features/shared/marketplace/controllers/marketplace_controller.dart:116 // MarketplaceController
  • lib/src/features/shared/marketplace/controllers/marketplace_controller.dart:145 // _fetchProducts
  • lib/src/features/shared/marketplace/controllers/marketplace_controller.dart:282 // clearWarning hack
  • lib/src/features/shared/marketplace/controllers/marketplace_controller.dart:432 // _extractFilters

API Calls

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

Notes

The 100+ lines of inline comments inside ProductListState.copyWith document a real frustration with warningMessage clearing — read those before refactoring.