copyWith method
AdapterRequest
copyWith({
- String? baseUrl,
- String? path,
- HttpMethod? method,
- Map<
String, dynamic> ? pathParams, - Map<
String, dynamic> ? queryParams, - Map<
String, dynamic> ? bodyParams, - dynamic rawBody,
- Map<
String, dynamic> ? headers, - String? contentType,
- ResponseType? responseType,
- Duration? connectTimeout,
- Duration? receiveTimeout,
- Duration? sendTimeout,
- CancelToken? cancelToken,
- 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,
dynamic rawBody,
Map<String, dynamic>? headers,
String? contentType,
ResponseType? responseType,
Duration? connectTimeout,
Duration? receiveTimeout,
Duration? sendTimeout,
CancelToken? cancelToken,
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: rawBody ?? this.rawBody,
headers: headers ?? this.headers,
contentType: contentType ?? this.contentType,
responseType: responseType ?? this.responseType,
connectTimeout: connectTimeout ?? this.connectTimeout,
receiveTimeout: receiveTimeout ?? this.receiveTimeout,
sendTimeout: sendTimeout ?? this.sendTimeout,
cancelToken: cancelToken ?? this.cancelToken,
extra: extra ?? this.extra,
);
}