incrementItem method

void incrementItem(
  1. String upc
)

Increases the quantity of an existing basket item by 1.

Searches basket for an item with matching upc, increments its 'qty' field, and updates the category's used count in balances.

Does nothing if:

  • No user is logged in
  • Item not found in basket
  • Category limit would be exceeded

Side effects:

Implementation

void incrementItem(String upc) {
  if (_uid == null) return;
  final i = basket.indexWhere((e) => e['upc'] == upc);
  if (i < 0) return;

  final cat = _canon(basket[i]['category'] as String);
  _ensureCategoryInit(cat);
  if (!_canAddCanon(cat)) return;

  basket[i]['qty'] = (basket[i]['qty'] ?? 1) + 1;
  balances[cat]!['used'] = (balances[cat]!['used'] ?? 0) + 1;

  // ignore: discarded_futures
  _persist();
  notifyListeners();
}