copyWith method

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

Create a Option from current instance with merging attributes.

Implementation

Options copyWith({
  String? method,
  Duration? sendTimeout,
  Duration? receiveTimeout,
  Map<String, Object?>? extra,
  Map<String, Object?>? headers,
  bool? preserveHeaderCase,
  ResponseType? responseType,
  String? contentType,
  ValidateStatus? validateStatus,
  bool? receiveDataWhenStatusError,
  bool? followRedirects,
  int? maxRedirects,
  bool? persistentConnection,
  RequestEncoder? requestEncoder,
  ResponseDecoder? responseDecoder,
  ListFormat? listFormat,
}) {
  Map<String, dynamic>? effectiveHeaders;
  if (headers == null && this.headers != null) {
    effectiveHeaders = 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>? effectiveExtra;
  if (extra == null && this.extra != null) {
    effectiveExtra = Map.from(this.extra!);
  }

  return Options(
    method: method ?? this.method,
    sendTimeout: sendTimeout ?? this.sendTimeout,
    receiveTimeout: receiveTimeout ?? this.receiveTimeout,
    extra: extra ?? effectiveExtra,
    headers: headers ?? effectiveHeaders,
    preserveHeaderCase: preserveHeaderCase ?? this.preserveHeaderCase,
    responseType: responseType ?? this.responseType,
    contentType: contentType ?? this.contentType,
    validateStatus: validateStatus ?? this.validateStatus,
    receiveDataWhenStatusError:
        receiveDataWhenStatusError ?? this.receiveDataWhenStatusError,
    followRedirects: followRedirects ?? this.followRedirects,
    maxRedirects: maxRedirects ?? this.maxRedirects,
    persistentConnection: persistentConnection ?? this.persistentConnection,
    requestEncoder: requestEncoder ?? this.requestEncoder,
    responseDecoder: responseDecoder ?? this.responseDecoder,
    listFormat: listFormat ?? this.listFormat,
  );
}