addHeader method Null safety

void addHeader(
  1. String name,
  2. APIHeader? header
)

Adds a header to headers for name.

If headers is null, it is created. If the key does not exist in headers, header is added for the key. If the key exists, header is not added. (To replace a header, access headers directly.)

Implementation

void addHeader(String name, APIHeader? header) {
  headers ??= {};
  if (!headers!.containsKey(name)) {
    headers![name] = header;
  }
}