copyWith method

BaseResponse copyWith({
  1. int? statusCode,
  2. BaseRequest? request,
  3. Map<String, String>? headers,
  4. bool? isRedirect,
  5. bool? persistentConnection,
  6. String? reasonPhrase,
  7. String? body,
  8. Stream<List<int>>? stream,
  9. int? contentLength,
  10. HttpClientResponse? inner,
})

Creates a new instance of BaseResponse based of on this. It copies all the properties and overrides the ones sent via parameters.

body are only copied if this is a Response instance.

stream and contentLength are only copied if this is a StreamedResponse instance.

inner are only copied if this is a IOStreamedResponse instance.

Implementation

BaseResponse copyWith({
  int? statusCode,
  BaseRequest? request,
  Map<String, String>? headers,
  bool? isRedirect,
  bool? persistentConnection,
  String? reasonPhrase,
  // `Response` only variables.
  String? body,
  // `StreamedResponse` only properties.
  Stream<List<int>>? stream,
  int? contentLength,
  // `IOStreamedResponse` only properties.
  HttpClientResponse? inner,
}) {
  if (this is Response) {
    return ResponseCopyWith(this as Response).copyWith(
      statusCode: statusCode,
      body: body,
      request: request,
      headers: headers,
      isRedirect: isRedirect,
      persistentConnection: persistentConnection,
      reasonPhrase: reasonPhrase,
    );
  } else if (this is StreamedResponse) {
    return StreamedResponseCopyWith(this as StreamedResponse).copyWith(
      stream: stream,
      statusCode: statusCode,
      contentLength: contentLength,
      request: request,
      headers: headers,
      isRedirect: isRedirect,
      persistentConnection: persistentConnection,
      reasonPhrase: reasonPhrase,
    );
  } else if (this is IOStreamedResponse) {
    return IOStreamedResponseCopyWith(this as IOStreamedResponse).copyWith(
      stream: stream,
      statusCode: statusCode,
      contentLength: contentLength,
      request: request,
      headers: headers,
      isRedirect: isRedirect,
      persistentConnection: persistentConnection,
      reasonPhrase: reasonPhrase,
      inner: inner,
    );
  }

  throw UnsupportedError(
      'Cannot copy unsupported type of response $runtimeType');
}