NotificationContent.fromJson constructor

NotificationContent.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory NotificationContent.fromJson(Map<String, dynamic> json) {
  final userInfo = json['userInfo'] as Map<String, dynamic>? ?? {};

  return NotificationContent(
    attachments: (json['attachments'] as List<dynamic>?)
        ?.map((e) => NotificationAttachment.fromJson(e))
        .toList(),
    badge: json['badge'],
    body: json['body'],
    categoryIdentifier: json['categoryIdentifier'],
    launchImageName: json['launchImageName'],
    sound: json['sound']?.toString(),
    subtitle: json['subtitle'],
    threadIdentifier: json['threadIdentifier'],
    title: json['title'],
    userInfo: userInfo,
    payload: userInfo.containsKey('payload')
        ? NotificationPayload.fromJson(userInfo['payload'])
        : null,
    customData: userInfo.containsKey('custom_data')
        ? NotificationCustomData.fromJson(userInfo['custom_data'])
        : null,
    summaryArgument: json['summaryArgument'],
    summaryArgumentCount: json['summaryArgumentCount'],
    targetContentIdentifier: json['targetContentIdentifier'],
    interruptionLevel: json['interruptionLevel']?.toString(),
    relevanceScore: (json['relevanceScore'] != null)
        ? (json['relevanceScore'] as num).toDouble()
        : null,
    filterCriteria: json['filterCriteria'],
  );
}