buildContact method
Builds a full contact object.
firstName is the first name.
lastName is the last name.
phoneNumber is the phone number.
email is an optional email address.
Returns a complete contact object.
Implementation
Contact buildContact({
required String firstName,
String? lastName,
required String phoneNumber,
String? email,
}) {
if (!isValidPhoneNumber(phoneNumber)) {
throw MessageException.invalidRecipient('Invalid phone number format');
}
final phones = [
Phone(phone: phoneNumber),
];
final emails = email != null && email.isNotEmpty
? [Email(email: email)]
: <Email>[];
return Contact(
firstName: firstName,
lastName: lastName,
phones: phones,
emails: emails,
);
}