consentStatusFromJson function
Converts a consent status string to a ConsentStatus enumeration value.
This function takes a consent status string as input and converts it into a
corresponding ConsentStatus enumeration value. It checks if the input
consentString is null, empty, or equal to '''', and if so, it returns
ConsentStatus.UNKNOWN. Otherwise, it uses the firstWhere method to search
through the ConsentStatus.values enumeration and find a match based on the
name property in a case-insensitive manner. If a match is found, the matching
ConsentStatus value is returned. If no match is found, it returns ConsentStatus.UNKNOWN.
@param consentString The consent status string to convert.
@return A ConsentStatus enumeration value corresponding to the input string.
Implementation
ConsentStatus consentStatusFromJson(String? consentString) {
if (consentString == null || consentString.isEmpty || consentString == '') {
return ConsentStatus.UNKNOWN;
}
return ConsentStatus.values.firstWhere(
(ConsentStatus consentStatus) {
return consentStatus.name == consentString.toUpperCase();
},
orElse: () => ConsentStatus.UNKNOWN,
);
}