Skip to content

Notifications Providers

Source: pharmanet/lib/core/providers/notification_provider.dart

Provider Reference

Provider Type Description
notificationServiceProvider Provider<NotificationService> Singleton service
notificationsProvider FutureProvider<List<AppNotification>> User notifications
unreadCountProvider FutureProvider<int> Unread notification count

Usage

// Fetch notifications
final notificationsAsync = ref.watch(notificationsProvider);

// Show unread badge count
final unread = ref.watch(unreadCountProvider);
if (unread > 0) Badge(child: Icon(Icons.notifications), label: Text('$unread'));

// Create notification (service)
final notificationService = ref.read(notificationServiceProvider);
await notificationService.createNotification(
  userId: userId,
  type: 'order_status',
  title: 'Order Shipped',
  message: 'Your order #123 is on its way!',
  relatedId: orderId,
  relatedType: 'order',
);

Service Methods

Source: pharmanet/lib/core/services/notification_service.dart

Method Description
createNotification(...) Insert single notification
createBulkNotifications(userIds, ...) Insert for multiple users
notifySellers(orderId, sellerIds) Notify sellers of new order
notifyAdmins(title, message, ...) Notify all admin users