contactTypeFromJson function

ContactType contactTypeFromJson(
  1. String? contactString
)

Converts a contact type string to a ContactType enumeration value.

This function takes a contact type string as input and converts it into a corresponding ContactType enumeration value. It checks if the input contactString is null, empty, or equal to 'UNKNOWN', and if so, it returns ContactType.UNKNOWN. Otherwise, it uses a where clause to search through the ContactType.values enumeration and find a match based on the name property, case-insensitively. The function then returns the matching ContactType value. If no match is found, it returns ContactType.UNKNOWN.

@param contactString The contact type string to convert. @return A ContactType enumeration value corresponding to the input string.

Implementation

ContactType contactTypeFromJson(String? contactString) {
  if (contactString == null ||
      contactString.isEmpty ||
      contactString == UNKNOWN) {
    return ContactType.UNKNOWN;
  }
  return ContactType.values.where((ContactType contactType) {
    return contactType.name.toLowerCase() == contactString.toLowerCase();
  }).first;
}