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