copyWith method
AdapterRequest
copyWith({
- String? baseUrl,
- String? path,
- HttpMethod? method,
- Map<
String, dynamic> ? pathParams, - Map<
String, dynamic> ? queryParams, - Map<
String, dynamic> ? bodyParams, - Object? rawBody = _unset,
- Map<
String, dynamic> ? headers, - Object? contentType = _unset,
- ResponseType? responseType,
- Object? connectTimeout = _unset,
- Object? receiveTimeout = _unset,
- Object? sendTimeout = _unset,
- Object? cancelToken = _unset,
- Map<
String, dynamic> ? extra,
Creates a copy of this request with some fields replaced.
This is useful for modifying requests in interceptors or creating variations of a base request.
Example:
final baseRequest = AdapterRequest(
baseUrl: 'https://api.example.com',
path: '/users',
method: HttpMethod.get,
);
// Add authentication header
final authenticatedRequest = baseRequest.copyWith(
headers: {...baseRequest.headers, 'Authorization': 'Bearer token'},
);
Implementation
AdapterRequest copyWith({
String? baseUrl,
String? path,
HttpMethod? method,
Map<String, dynamic>? pathParams,
Map<String, dynamic>? queryParams,
Map<String, dynamic>? bodyParams,
Object? rawBody = _unset,
Map<String, dynamic>? headers,
Object? contentType = _unset,
ResponseType? responseType,
Object? connectTimeout = _unset,
Object? receiveTimeout = _unset,
Object? sendTimeout = _unset,
Object? cancelToken = _unset,
Map<String, dynamic>? extra,
}) {
return AdapterRequest(
baseUrl: baseUrl ?? this.baseUrl,
path: path ?? this.path,
method: method ?? this.method,
pathParams: pathParams ?? this.pathParams,
queryParams: queryParams ?? this.queryParams,
bodyParams: bodyParams ?? this.bodyParams,
rawBody: identical(rawBody, _unset) ? this.rawBody : rawBody,
headers: headers ?? this.headers,
contentType: identical(contentType, _unset)
? this.contentType
: contentType as String?,
responseType: responseType ?? this.responseType,
connectTimeout: identical(connectTimeout, _unset)
? this.connectTimeout
: connectTimeout as Duration?,
receiveTimeout: identical(receiveTimeout, _unset)
? this.receiveTimeout
: receiveTimeout as Duration?,
sendTimeout: identical(sendTimeout, _unset)
? this.sendTimeout
: sendTimeout as Duration?,
cancelToken: identical(cancelToken, _unset)
? this.cancelToken
: cancelToken as CancelToken?,
extra: extra ?? this.extra,
);
}