addHeader method Null safety

void addHeader(
  1. String name,
  2. String? value,
  3. [HeaderEncoding encoding = HeaderEncoding.none]
)

Adds a header with the specified name, value and optional encoding.

Implementation

void addHeader(String name, String? value,
    [HeaderEncoding encoding = HeaderEncoding.none]) {
  headers ??= <Header>[];
  var localValue = value;
  if (value != null) {
    if (encoding == HeaderEncoding.Q) {
      localValue = MailCodec.quotedPrintable
          .encodeHeader(value, nameLength: name.length);
    } else if (encoding == HeaderEncoding.B) {
      localValue =
          MailCodec.base64.encodeHeader(value, nameLength: name.length);
    }
  }
  final header = Header(name, localValue, encoding);
  headers!.add(header);
}