NetmeraPushObject.fromJson constructor
NetmeraPushObject.fromJson(
- Map json
Implementation
factory NetmeraPushObject.fromJson(Map<dynamic, dynamic> json) {
// interactiveActions may arrive as a List or a JSON string — both handled for transition safety
List<NetmeraInteractiveAction> actions = const [];
final rawActions = json['interactiveActions'];
if (rawActions is List) {
actions = rawActions
.whereType<Map>()
.map((e) => NetmeraInteractiveAction.fromJson(e))
.toList();
} else if (rawActions is String) {
try {
final decoded = jsonDecode(rawActions) as List;
actions = decoded
.whereType<Map>()
.map((e) => NetmeraInteractiveAction.fromJson(e))
.toList();
} catch (_) {}
}
List<NetmeraCarouselObject> carouselItems = const [];
final rawCarousel = json['carousel'];
if (rawCarousel is List) {
carouselItems = rawCarousel
.map((e) => NetmeraCarouselObject.fromJson(e))
.toList();
}
return NetmeraPushObject(
pushType: NetmeraPushType.fromInt(json['pushType'] as int?),
pushId: json['pushId'] as String?,
pushInstanceId: json['pushInstanceId'] as String?,
inboxStatus: json['inboxStatus'] as int?,
category: json['category'] as String?,
categories: json['categories'] as List<dynamic>?,
customJson: json['customJson'] as Map<dynamic, dynamic>?,
title: json['title'] as String?,
subtitle: json['subtitle'] as String?,
body: json['body'] as String?,
mediaAttachmentURL: json['mediaAttachmentURL'] as String?,
externalId: json['externalId'] as String?,
sendDate: json['sendDate'] as String?,
expireTime: json['expireTime'] as String?,
pushAction: json['pushAction'] != null
? NetmeraPushAction.fromJson(json['pushAction'])
: null,
deepLinkUrl: json['action_deeplink_url'] as String?,
webPageUrl: json['action_webpage_url'] as String?,
interactiveActions: actions,
carousel: carouselItems,
);
}