Promotions Providers¶
Source: pharmanet/lib/core/providers/promotion_provider.dart
Provider Reference¶
| Provider | Type | Description |
|---|---|---|
activePromotionsProvider |
FutureProvider<List<Promotion>> |
Currently active promotions |
promotionDetailsProvider |
FutureProvider.family<Promotion, String> |
Single promotion detail |
activeOffersProvider |
FutureProvider<List<OfferProduct>> |
All active offers |
activeOffersMapProvider |
Provider<Map<String, OfferProduct>> |
Key provider — productId → offer lookup map |
offersByPromotionProvider |
FutureProvider.family<List<OfferProduct>, String> |
Offers for a promotion |
offersByProductProvider |
FutureProvider.family<List<OfferProduct>, String> |
Offers for a product |
activeOffersMapProvider (Key Provider)¶
final activeOffersMapProvider = Provider<Map<String, OfferProduct>>((ref) {
final offersAsync = ref.watch(activeOffersProvider);
return offersAsync.valueOrNull?.fold({}, (map, offer) {
map[offer.productId] = offer;
return map;
}) ?? {};
});
This provider is consumed by ProductCard, ProductHeaderInfo, and ProductDetailsPage to show offer pricing on any product display.
Usage¶
// Get best offer for a product
final offersMap = ref.watch(activeOffersMapProvider);
final offer = offersMap[product.id];
if (offer != null) {
// Show offer price with strikethrough
Text('${offer.offerPrice} ETB', style: TextStyle(color: Colors.green));
Text('${offer.originalPrice} ETB', style: TextStyle(decoration: TextDecoration.lineThrough));
}
Related¶
- Promotions & Offers Feature — UI integration
- Promotion Model — Data model