NotificationEntity.fromMap constructor

NotificationEntity.fromMap(
  1. Map<String, dynamic> map
)

Creates a notification entity from a map.

Implementation

factory NotificationEntity.fromMap(Map<String, dynamic> map) {
  return NotificationEntity(
    id: map.parseDefault<String>('id', ''),
    title: map.parseDefault<String>('title', ''),
    body: map.parseDefault<String>('body', ''),
    data: map.parseDefault<Map<String, dynamic>>('data', <String, dynamic>{}),
    imageUrl: map.parse<String>('imageUrl'),
    icon: map.parse<String>('icon'),
    channelId: map.parse<String>('channelId'),
    timestamp: map.parse<DateTime>('timestamp') ?? DateTime.now(),
    isDelivered: map.parseDefault<bool>('isDelivered', false),
    isRead: map.parseDefault<bool>('isRead', false),
    deliveryTime: map.parse<DateTime>('deliveryTime'),
    openedTime: map.parse<DateTime>('openedTime'),
    source: NotificationSource.values.firstWhere(
      (NotificationSource e) => e.name.compareWithoutCase(
        map.parseDefault<String>('source', NotificationSource.local.name),
      ),
      orElse: () => NotificationSource.local,
    ),
  );
}