elementFromDictionary static method

MBElement elementFromDictionary(
  1. Map<String, dynamic> dictionary
)

Returns the specialized MBElement from the dictionary returned by the API.

Implementation

static MBElement elementFromDictionary(Map<String, dynamic> dictionary) {
  String typeString = dictionary['type'] as String;
  MBElementType type = MBElementsUtilities.elementTypeFromString(typeString);
  switch (type) {
    case MBElementType.text:
      return MBTextElement(dictionary: dictionary);
    case MBElementType.images:
      return MBImagesElement(dictionary: dictionary);
    case MBElementType.checkbox:
      return MBCheckboxElement(dictionary: dictionary);
    case MBElementType.address:
      return MBAddressElement(dictionary: dictionary);
    case MBElementType.poll:
      return MBPollElement(dictionary: dictionary);
    case MBElementType.markdown:
      return MBMarkdownElement(dictionary: dictionary);
    case MBElementType.dropdown:
      return MBDropdownElement(dictionary: dictionary);
    case MBElementType.media:
      return MBMediaElement(dictionary: dictionary);
    case MBElementType.date:
      return MBDateElement(dictionary: dictionary);
    case MBElementType.relation:
      return MBRelationElement(dictionary: dictionary);
    case MBElementType.color:
      return MBColorElement(dictionary: dictionary);
    case MBElementType.shopifyCollection:
      return MBShopifyCollectionElement(dictionary: dictionary);
    case MBElementType.custom:
      return MBCustomElement(dictionary: dictionary);
    default:
      return MBGeneralElement(dictionary: dictionary);
  }
}