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