get method
Sends a GET request to the specified url
.
url
: The request URL.queryParameters
: Optional URL query parameters.options
: DioOptions
for this specific request (e.g., headers, response type). These will be merged withcacheOptions
.cancelToken
: OptionalCancelToken
to allow cancelling the request externally.onReceiveProgress
: Optional callback for tracking download progress.cacheOptions
: OptionalCacheOptions
specific to this request. If null, globalCacheOptions will be used (if available).
Returns a Future<Response> containing the raw Dio response upon success.
Throws a NetworkException (or one of its subtypes like NetworkTimeoutException, NetworkResponseException, etc.) on failure.
Implementation
Future<Response> get(
String url, {
Map<String, dynamic>? queryParameters,
Options? options,
CancelToken? cancelToken,
ProgressCallback? onReceiveProgress,
CacheOptions? cacheOptions,
}) async {
try {
final Response response = await _dio.get(
url,
queryParameters: queryParameters,
options: _mergeDioAndCacheOptions(
dioOptions: options,
cacheOptions: cacheOptions ?? globalCacheOptions,
),
cancelToken: cancelToken, // Pass token directly
onReceiveProgress: onReceiveProgress,
);
return response;
} on DioException catch (e) {
// Convert DioException to a specific NetworkException
throw _handleDioError(e);
}
// Catch other potential errors during request processing, though less common
catch (e) {
throw UnknownNetworkErrorException(
message:
'Unexpected error during GET request processing: $e', // $METHOD = GET/POST etc.
code: NetworkErrorCode.unknownError, // Use specific code
originalError: e,
);
}
}