copyWith method

RequestOptions copyWith({
  1. String? method,
  2. int? sendTimeout,
  3. int? receiveTimeout,
  4. int? connectTimeout,
  5. dynamic data,
  6. String? path,
  7. Map<String, dynamic>? queryParameters,
  8. String? baseUrl,
  9. ProgressCallback? onReceiveProgress,
  10. ProgressCallback? onSendProgress,
  11. CancelToken? cancelToken,
  12. Map<String, dynamic>? extra,
  13. Map<String, dynamic>? headers,
  14. ResponseType? responseType,
  15. String? contentType,
  16. ValidateStatus? validateStatus,
  17. bool? receiveDataWhenStatusError,
  18. bool? followRedirects,
  19. int? maxRedirects,
  20. RequestEncoder? requestEncoder,
  21. ResponseDecoder? responseDecoder,
  22. ListFormat? listFormat,
  23. bool? setRequestContentTypeWhenNoPayload,
})

Create a Option from current instance with merging attributes.

Implementation

RequestOptions copyWith({
  String? method,
  int? sendTimeout,
  int? receiveTimeout,
  int? connectTimeout,
  dynamic data,
  String? path,
  Map<String, dynamic>? queryParameters,
  String? baseUrl,
  ProgressCallback? onReceiveProgress,
  ProgressCallback? onSendProgress,
  CancelToken? cancelToken,
  Map<String, dynamic>? extra,
  Map<String, dynamic>? headers,
  ResponseType? responseType,
  String? contentType,
  ValidateStatus? validateStatus,
  bool? receiveDataWhenStatusError,
  bool? followRedirects,
  int? maxRedirects,
  RequestEncoder? requestEncoder,
  ResponseDecoder? responseDecoder,
  ListFormat? listFormat,
  bool? setRequestContentTypeWhenNoPayload,
}) {
  var contentTypeInHeader = headers != null &&
      headers.keys
          .map((e) => e.toLowerCase())
          .contains(Headers.contentTypeHeader);

  assert(
    !(contentType != null && contentTypeInHeader),
    'You cannot set both contentType param and a content-type header',
  );

  var ro = RequestOptions(
    method: method ?? this.method,
    sendTimeout: sendTimeout ?? this.sendTimeout,
    receiveTimeout: receiveTimeout ?? this.receiveTimeout,
    connectTimeout: connectTimeout ?? this.connectTimeout,
    data: data ?? this.data,
    path: path ?? this.path,
    baseUrl: baseUrl ?? this.baseUrl,
    queryParameters: queryParameters ?? Map.from(this.queryParameters),
    onReceiveProgress: onReceiveProgress ?? this.onReceiveProgress,
    onSendProgress: onSendProgress ?? this.onSendProgress,
    cancelToken: cancelToken ?? this.cancelToken,
    extra: extra ?? Map.from(this.extra),
    headers: headers ?? Map.from(this.headers),
    responseType: responseType ?? this.responseType,
    validateStatus: validateStatus ?? this.validateStatus,
    receiveDataWhenStatusError:
        receiveDataWhenStatusError ?? this.receiveDataWhenStatusError,
    followRedirects: followRedirects ?? this.followRedirects,
    maxRedirects: maxRedirects ?? this.maxRedirects,
    requestEncoder: requestEncoder ?? this.requestEncoder,
    responseDecoder: responseDecoder ?? this.responseDecoder,
    listFormat: listFormat ?? this.listFormat,
  );

  if (contentType != null) {
    ro.headers.remove(Headers.contentTypeHeader);
    ro.contentType = contentType;
  } else if (!contentTypeInHeader) {
    ro.contentType = this.contentType;
  }

  return ro;
}