copyWith method

BaseRequest copyWith({
  1. String? method,
  2. Uri? url,
  3. Map<String, String>? headers,
  4. bool? followRedirects,
  5. int? maxRedirects,
  6. bool? persistentConnection,
  7. dynamic body,
  8. Encoding? encoding,
  9. Map<String, String>? fields,
  10. List<MultipartFile>? files,
  11. Stream<List<int>>? stream,
})

Implementation

BaseRequest copyWith({
  String? method,
  Uri? url,
  Map<String, String>? headers,
  bool? followRedirects,
  int? maxRedirects,
  bool? persistentConnection,
  // Request only variables.
  dynamic body,
  Encoding? encoding,
  // MultipartRequest only properties.
  Map<String, String>? fields,
  List<MultipartFile>? files,
  // StreamedRequest only properties.
  Stream<List<int>>? stream,
}) {
  if (this is Request) {
    return RequestCopyWith(this as Request).copyWith(
      method: method,
      url: url,
      headers: headers,
      body: body,
      encoding: encoding,
      followRedirects: followRedirects,
      maxRedirects: maxRedirects,
      persistentConnection: persistentConnection,
    );
  } else if (this is StreamedRequest) {
    return StreamedRequestCopyWith(this as StreamedRequest).copyWith(
      method: method,
      url: url,
      headers: headers,
      stream: stream,
      followRedirects: followRedirects,
      maxRedirects: maxRedirects,
      persistentConnection: persistentConnection,
    );
  } else if (this is MultipartRequest) {
    return MultipartRequestCopyWith(this as MultipartRequest).copyWith(
      method: method,
      url: url,
      headers: headers,
      fields: fields,
      files: files,
      followRedirects: followRedirects,
      maxRedirects: maxRedirects,
      persistentConnection: persistentConnection,
    );
  }

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