Skip to content

Notifications

Source: pharmanet/lib/features/public/ + core/services/

Pages

Page File Description
NotificationsPage features/public/presentation/pages/notifications_page.dart Full notification list (consumer)
PublicNotificationsPage features/public/presentation/pages/public_notifications_page.dart Alternative notification list

Providers

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

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

Notification Service (Flutter)

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

Method Description
createNotification(userId, type, title, message, relatedId, relatedType, data) Insert a notification
createBulkNotifications(userIds, type, title, message) Insert for multiple users
notifySellers(orderId, sellerIds) Notify sellers of new order
notifyAdmins(title, message, type, relatedId, relatedType) Notify admin users

FCM Integration

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

Method Description
initialize() Request permissions, get FCM token, configure local notifications
updateToken() Refresh FCM token and save to profile

Initialization

class FirebaseNotificationService {
  Future<void> initialize() async {
    // Request permissions
    final messaging = FirebaseMessaging.instance;
    await messaging.requestPermission();

    // Get FCM token and save to profile
    final token = await messaging.getToken();
    await _saveTokenToProfile(token);

    // Configure local notifications
    const androidSettings = AndroidInitializationSettings('@mipmap/ic_launcher');
    const iosSettings = DarwinInitializationSettings();
    await flutterLocalNotificationsPlugin.initialize(
      const InitializationSettings(android: androidSettings, iOS: iosSettings),
    );

    // Handle foreground messages
    FirebaseMessaging.onMessage.listen(_handleForegroundMessage);

    // Handle notification taps (from terminated/background)
    messaging.getInitialMessage().then(_handleNotificationTap);
    FirebaseMessaging.onMessageOpenedApp.listen(_handleNotificationTap);
  }
}

Notification Types

Type Trigger Recipients
order_created Customer places order Sellers + Admins
order_status Seller/admin updates status Customer
product_approved Admin approves product Seller
product_rejected Admin rejects product Seller
pharmacy_approved Admin approves pharmacy Applicant
pharmacy_rejected Admin rejects pharmacy Applicant
promotion_activated Admin activates promotion All customers
offer_created Seller creates offer Admins
system General system notification Targeted user

Notification List UI

The NotificationsPage shows: - Unread items with bold title + colored indicator - Tap → navigate to related entity (order detail, product detail, etc.) - "Mark all as read" button - Timestamp display - Empty state when no notifications