substitutes method
Finds WIC-eligible substitute products in the same category.
Queries the apl collection for products matching the given category
where eligible is true. Results are limited to max items (default 3).
This is useful when a user's preferred product would exceed their category limit, allowing the app to suggest alternatives.
Parameters:
category: The product category to search withinmax: Maximum number of substitutes to return (default: 3)
Returns a List of product Maps with the same structure as findByUpc.
Implementation
Future<List<Map<String, dynamic>>> substitutes(
String category, {
int max = 3,
}) async {
final query = await _db
.collection('apl')
.where('category', isEqualTo: category)
.where('eligible', isEqualTo: true)
.limit(max)
.get();
return query.docs.map((d) => d.data()).toList();
}