copyWith method
RequestOptions
copyWith({
- String? method,
- Duration? sendTimeout,
- Duration? receiveTimeout,
- Duration? 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, - bool? preserveHeaderCase,
- ResponseType? responseType,
- String? contentType,
- ValidateStatus? validateStatus,
- bool? receiveDataWhenStatusError,
- bool? followRedirects,
- int? maxRedirects,
- bool? persistentConnection,
- RequestEncoder? requestEncoder,
- ResponseDecoder? responseDecoder,
- ListFormat? listFormat,
- bool? setRequestContentTypeWhenNoPayload,
Create a RequestOptions from current instance with merged attributes.
Implementation
RequestOptions copyWith({
String? method,
Duration? sendTimeout,
Duration? receiveTimeout,
Duration? 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,
bool? preserveHeaderCase,
ResponseType? responseType,
String? contentType,
ValidateStatus? validateStatus,
bool? receiveDataWhenStatusError,
bool? followRedirects,
int? maxRedirects,
bool? persistentConnection,
RequestEncoder? requestEncoder,
ResponseDecoder? responseDecoder,
ListFormat? listFormat,
bool? setRequestContentTypeWhenNoPayload,
}) {
final 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',
);
final 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),
preserveHeaderCase: preserveHeaderCase ?? this.preserveHeaderCase,
responseType: responseType ?? this.responseType,
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,
sourceStackTrace: sourceStackTrace,
);
if (contentType != null) {
ro.headers.remove(Headers.contentTypeHeader);
ro.contentType = contentType;
} else if (!contentTypeInHeader) {
ro.contentType = this.contentType;
}
return ro;
}