NexusInAppMessage.fromJson constructor

NexusInAppMessage.fromJson(
  1. Map<String, dynamic> j
)

Implementation

factory NexusInAppMessage.fromJson(Map<String, dynamic> j) {
  final content = (j['content'] as Map?)?.cast<String, dynamic>() ?? const {};
  final trigger = (j['trigger'] as Map?)?.cast<String, dynamic>();
  final buttons = (j['buttons'] as List?)
          ?.whereType<Map>()
          .map((b) => NexusInAppButton.fromJson(b.cast<String, dynamic>()))
          .toList() ??
      const <NexusInAppButton>[];
  return NexusInAppMessage(
    id: (j['id'] ?? '').toString(),
    layout: (j['layout'] ?? 'modal').toString(),
    title: content['title']?.toString(),
    body: content['body']?.toString(),
    imageUrl: content['imageUrl']?.toString(),
    backgroundColor: content['backgroundColor']?.toString(),
    textColor: content['textColor']?.toString(),
    buttons: buttons,
    triggerType: trigger?['type']?.toString(),
    triggerEvent: trigger?['event']?.toString(),
    maxDisplays: (j['maxDisplays'] as num?)?.toInt(),
    perSession: j['perSession'] == true,
  );
}