MBEventTrigger.fromDictionary constructor

MBEventTrigger.fromDictionary(
  1. Map<String, dynamic> dictionary
)

Initializes an event trigger with the data of the dictionary returned by the APIs.

Implementation

factory MBEventTrigger.fromDictionary(Map<String, dynamic> dictionary) {
  String id = dictionary['id'] ?? '';
  String event = dictionary['event_name'] ?? '';

  int times = 1;
  if (dictionary['times'] is int) {
    times = dictionary['times'];
  } else if (dictionary['times'] is String) {
    times = int.tryParse(dictionary['times']) ?? 1;
  }

  Map<String, dynamic>? metadata;
  if (dictionary['metadata'] is Map) {
    metadata = dictionary['metadata'];
  }

  return MBEventTrigger(
    id: id,
    event: event,
    times: times,
    metadata: metadata,
  );
}