MBMessageTriggers.fromJsonDictionary constructor

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

Creates and initializes the trigger with a saved JSON dictionary.

Implementation

factory MBMessageTriggers.fromJsonDictionary(
    Map<String, dynamic> dictionary) {
  String methodString = dictionary['method'];
  MBMessageTriggersMethod method =
      MBMessageTriggers._triggersMethodFromString(methodString);

  List<MBTrigger> triggers = [];
  if (dictionary['triggers'] != null) {
    if (dictionary['triggers'] is List) {
      List<Map<String, dynamic>> triggersDictionaries =
          List.castFrom<dynamic, Map<String, dynamic>>(
              dictionary['triggers']);
      triggers = triggersDictionaries
          .map(
              (t) => MBAutomationMessagesManager.triggerFromJsonDictionary(t))
          .toList();
    }
  }
  return MBMessageTriggers(
    method: method,
    triggers: triggers,
  );
}