copyWith method

Options copyWith({
  1. String? method,
  2. int? sendTimeout,
  3. int? receiveTimeout,
  4. Map<String, dynamic>? extra,
  5. Map<String, dynamic>? headers,
  6. ResponseType? responseType,
  7. String? contentType,
  8. ValidateStatus? validateStatus,
  9. bool? receiveDataWhenStatusError,
  10. bool? followRedirects,
  11. int? maxRedirects,
  12. RequestEncoder? requestEncoder,
  13. ResponseDecoder? responseDecoder,
  14. ListFormat? listFormat,
})

Create a Option from current instance with merging attributes.

Implementation

Options copyWith({
  String? method,
  int? sendTimeout,
  int? receiveTimeout,
  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,
}) {
  Map<String, dynamic>? _headers;
  if (headers == null && this.headers != null) {
    _headers = caseInsensitiveKeyMap(this.headers!);
  }

  if (headers != null) {
    headers = caseInsensitiveKeyMap(headers);
    assert(
      !(contentType != null &&
          headers.containsKey(Headers.contentTypeHeader)),
      'You cannot set both contentType param and a content-type header',
    );
  }

  Map<String, dynamic>? _extra;
  if (extra == null && this.extra != null) {
    _extra = Map.from(this.extra!);
  }

  return Options(
    method: method ?? this.method,
    sendTimeout: sendTimeout ?? this.sendTimeout,
    receiveTimeout: receiveTimeout ?? this.receiveTimeout,
    extra: extra ?? _extra,
    headers: headers ?? _headers,
    responseType: responseType ?? this.responseType,
    contentType: contentType ?? this.contentType,
    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,
  );
}