getUserNotifications method

Future<List<NotificationModel>> getUserNotifications(
  1. String userId
)

Implementation

Future<List<NotificationModel>> getUserNotifications(String userId) async {
  final snapshot = await _firestore
      .collection('notifications')
      .where('userId', isEqualTo: userId)
      .orderBy('createdAt', descending: true)
      .limit(50)
      .get();

  return snapshot.docs.map((doc) {
    final notification = NotificationModel.fromFirestore(doc);
    // If server sent priority: "urgent", it will:
    // 1. Log: "Unknown NotificationPriority: urgent, using default: medium"
    // 2. Set priority to NotificationPriority.medium
    // 3. App continues working AND you know unknown values are appearing
    return notification;
  }).toList();
}