MBEventTrigger.fromJsonDictionary constructor
MBEventTrigger.fromJsonDictionary(
- Map<String, dynamic> dictionary
)
Implementation
@override
factory MBEventTrigger.fromJsonDictionary(Map<String, dynamic> dictionary) {
String id = dictionary['id'] ?? '';
String event = dictionary['event'] ?? '';
int times = 0;
if (dictionary['times'] is String) {
times = int.tryParse(dictionary['times']) ?? 0;
} else if (dictionary['times'] is int) {
times = dictionary['times'];
}
Map<String, dynamic>? metadata = dictionary['metadata'];
MBEventTrigger trigger = MBEventTrigger(
id: id,
event: event,
times: times,
metadata: metadata,
);
if (dictionary['completionDate'] != null) {
int completionDateTimestamp = dictionary['completionDate'];
trigger.completionDate =
DateTime.fromMicrosecondsSinceEpoch(completionDateTimestamp * 1000);
}
if (dictionary['numberOfTimes'] != null) {
trigger.numberOfTimes = dictionary['numberOfTimes'];
}
return trigger;
}