name property

Name name

Returns an individual's name as Name

Implementation

Name get name {
  String? givenName;
  String? surname;

  var foundGivenName = false;
  var foundSurname = false;

  for (final child in children) {
    if (child.tag == GEDCOM_TAG_NAME) {
      // Some GEDCOM files don't use child tags but instead
      // place the name in the value of the NAME tag.
      if (child.value != '') {
        final name = child.value!.split('/');
        if (name.isNotEmpty) {
          givenName = name[0].trim();
          if (name.length > 1) {
            surname = name[1].trim();
          }
        }
        return Name(givenName: givenName, surname: surname);
      }

      for (final childOfChild in child.children) {
        if (childOfChild.tag == GEDCOM_TAG_GIVEN_NAME) {
          givenName = childOfChild.value;
          foundGivenName = true;
        }
        if (childOfChild.tag == GEDCOM_TAG_SURNAME) {
          surname = childOfChild.value;
          foundSurname = true;
        }
      }
    }
    if (foundSurname && foundGivenName) {
      return Name(givenName: givenName, surname: surname);
    }
  }
  // If we reach here we are probably returning empty strings
  return Name(
    givenName: '',
    surname: '',
  );
}