MBMessageTriggers.fromDictionary constructor

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

Initializes message triggers with the data of the dictionary returned by the APIs.

Implementation

factory MBMessageTriggers.fromDictionary(Map<String, dynamic> dictionary) {
  String methodString = dictionary['method'];
  MBMessageTriggersMethod method = MBMessageTriggersMethod.all;
  if (methodString == 'all') {
    method = MBMessageTriggersMethod.all;
  } else if (methodString == 'any') {
    method = MBMessageTriggersMethod.any;
  }

  List<MBTrigger> triggers = [];
  if (dictionary['triggers'] != null && dictionary['triggers'] is List) {
    List triggersDict = dictionary['triggers'];
    for (dynamic triggerDict in triggersDict) {
      if (triggerDict is Map<String, dynamic>) {
        triggers.add(
            MBAutomationMessagesManager.triggerFromDictionary(triggerDict));
      }
    }
  }

  return MBMessageTriggers(
    method: method,
    triggers: triggers,
  );
}