put method
Sends a PUT request to the specified url
.
url
: The request URL.data
: Optional request body data.queryParameters
: Optional URL query parameters.options
: DioOptions
for this specific request. Merged withcacheOptions
.cancelToken
: OptionalCancelToken
for cancellation.onSendProgress
: Optional callback for tracking upload progress.onReceiveProgress
: Optional callback for tracking download progress.cacheOptions
: OptionalCacheOptions
specific to this request. Uses globalCacheOptions if null and available.
Returns a Future<Response> containing the raw Dio response upon success.
Throws a NetworkException subtype on failure.
Implementation
Future<Response> put(
String url, {
dynamic data,
Map<String, dynamic>? queryParameters,
Options? options,
CancelToken? cancelToken,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
CacheOptions? cacheOptions,
}) async {
try {
final Response response = await _dio.put(
url,
data: data,
queryParameters: queryParameters,
options: _mergeDioAndCacheOptions(
dioOptions: options,
cacheOptions: cacheOptions ?? globalCacheOptions,
),
cancelToken: cancelToken, // Pass token directly
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
return response;
} on DioException catch (e) {
throw _handleDioError(e);
} catch (e) {
throw UnknownNetworkErrorException(
message: 'Unexpected error during PUT request processing: $e',
code: NetworkErrorCode.unknownError, // Use specific code
originalError: e,
);
}
}