copyWith method Null safety

Request copyWith(
  1. {Uri? url,
  2. String? method,
  3. Map<String, String>? headers,
  4. Stream<List<int>>? bodyBytes,
  5. bool followRedirects = true,
  6. int maxRedirects = 4,
  7. int? contentLength,
  8. FormData? files,
  9. bool persistentConnection = true,
  10. Decoder<T>? decoder,
  11. bool appendHeader = true}
)

Implementation

Request copyWith({
  Uri? url,
  String? method,
  Map<String, String>? headers,
  Stream<List<int>>? bodyBytes,
  bool followRedirects = true,
  int maxRedirects = 4,
  int? contentLength,
  FormData? files,
  bool persistentConnection = true,
  Decoder<T>? decoder,
  bool appendHeader = true,
}) {
  if (followRedirects) {
    assert(maxRedirects > 0);
  }

  // If appendHeader is set to true, we will merge origin headers with that
  if (appendHeader && headers != null) {
    headers.addAll(this.headers);
  }

  return Request._(
    url: url ?? this.url,
    method: method ?? this.method,
    bodyBytes: bodyBytes ??= BodyBytesStream.fromBytes(const []),
    headers: headers == null ? this.headers : Map.from(headers),
    followRedirects: followRedirects,
    maxRedirects: maxRedirects,
    contentLength: contentLength,
    files: files,
    persistentConnection: persistentConnection,
    decoder: decoder,
  );
}