decode method

WebhookNewContactPayloadEventNameEnum? decode(
  1. dynamic data, {
  2. bool allowNull = true,
})

Decodes a data to a WebhookNewContactPayloadEventNameEnum.

If allowNull is true and the data cannot be decoded successfully, then null is returned. However, if allowNull is false and the data cannot be decoded successfully, then an UnimplementedError is thrown.

The allowNull is very handy when an API changes and a new enum value is added or removed, and users are still using an old app with the old code.

Implementation

WebhookNewContactPayloadEventNameEnum? decode(dynamic data, {bool allowNull = true}) {
  if (data != null) {
    switch (data) {
      case r'EMAIL_RECEIVED': return WebhookNewContactPayloadEventNameEnum.EMAIL_RECEIVED;
      case r'NEW_EMAIL': return WebhookNewContactPayloadEventNameEnum.NEW_EMAIL;
      case r'NEW_CONTACT': return WebhookNewContactPayloadEventNameEnum.NEW_CONTACT;
      case r'NEW_ATTACHMENT': return WebhookNewContactPayloadEventNameEnum.NEW_ATTACHMENT;
      case r'EMAIL_OPENED': return WebhookNewContactPayloadEventNameEnum.EMAIL_OPENED;
      case r'EMAIL_READ': return WebhookNewContactPayloadEventNameEnum.EMAIL_READ;
      case r'DELIVERY_STATUS': return WebhookNewContactPayloadEventNameEnum.DELIVERY_STATUS;
      case r'BOUNCE': return WebhookNewContactPayloadEventNameEnum.BOUNCE;
      case r'BOUNCE_RECIPIENT': return WebhookNewContactPayloadEventNameEnum.BOUNCE_RECIPIENT;
      case r'NEW_SMS': return WebhookNewContactPayloadEventNameEnum.NEW_SMS;
      default:
        if (!allowNull) {
          throw ArgumentError('Unknown enum value to decode: $data');
        }
    }
  }
  return null;
}