addRecipient method Null safety

void addRecipient(
  1. MailAddress recipient,
  2. {RecipientGroup group = RecipientGroup.to}
)

Adds a recipient.

Specify the group in case the recipient should not be added to the 'To' group. Compare removeRecipient and clearRecipients.

Implementation

void addRecipient(MailAddress recipient,
    {RecipientGroup group = RecipientGroup.to}) {
  switch (group) {
    case RecipientGroup.to:
      to ??= <MailAddress>[];
      to!.add(recipient);
      break;
    case RecipientGroup.cc:
      cc ??= <MailAddress>[];
      cc!.add(recipient);
      break;
    case RecipientGroup.bcc:
      bcc ??= <MailAddress>[];
      bcc!.add(recipient);
      break;
  }
}