relationshipFromJson function

Relationship relationshipFromJson(
  1. String? relationShipString
)

Converts a JSON relationship string to a corresponding Relationship enumeration.

This function takes a JSON relationship string as input and converts it to the corresponding Relationship enumeration. If the input string is null, empty, or matches the constant '', the function returns the default relationship Relationship.unknown. Otherwise, it searches through the Relationship enum values and compares their lowercase names with the lowercase input string to find a match. The first matching Relationship enum is returned. If no match is found, an exception will be thrown.

@param relationshipString The JSON relationship string to convert to a Relationship enum. @return A Relationship enum corresponding to the input relationship string.

Implementation

Relationship relationshipFromJson(String? relationShipString) {
  if (relationShipString == null ||
      relationShipString.isEmpty ||
      relationShipString == '') {
    return Relationship.unknown;
  }
  return Relationship.values.where((Relationship relationship) {
    return relationship.name.toLowerCase() == relationShipString.toLowerCase();
  }).first;
}