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,
})

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.

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,
}) {
  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,
    );
  }

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