decode method
Decodes a data
to a CreateWebhookOptionsEventNameEnum.
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
CreateWebhookOptionsEventNameEnum? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'EMAIL_RECEIVED': return CreateWebhookOptionsEventNameEnum.EMAIL_RECEIVED;
case r'NEW_EMAIL': return CreateWebhookOptionsEventNameEnum.NEW_EMAIL;
case r'NEW_CONTACT': return CreateWebhookOptionsEventNameEnum.NEW_CONTACT;
case r'NEW_ATTACHMENT': return CreateWebhookOptionsEventNameEnum.NEW_ATTACHMENT;
case r'EMAIL_OPENED': return CreateWebhookOptionsEventNameEnum.EMAIL_OPENED;
case r'EMAIL_READ': return CreateWebhookOptionsEventNameEnum.EMAIL_READ;
case r'DELIVERY_STATUS': return CreateWebhookOptionsEventNameEnum.DELIVERY_STATUS;
case r'BOUNCE': return CreateWebhookOptionsEventNameEnum.BOUNCE;
case r'BOUNCE_RECIPIENT': return CreateWebhookOptionsEventNameEnum.BOUNCE_RECIPIENT;
case r'NEW_SMS': return CreateWebhookOptionsEventNameEnum.NEW_SMS;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}