get method

Future<Response> get(
  1. String url, {
  2. Map<String, dynamic>? queryParameters,
  3. Options? options,
  4. CancelToken? cancelToken,
  5. ProgressCallback? onReceiveProgress,
  6. CacheOptions? cacheOptions,
})

Sends a GET request to the specified url.

  • url: The request URL.
  • queryParameters: Optional URL query parameters.
  • options: Dio Options for this specific request (e.g., headers, response type). These will be merged with cacheOptions.
  • cancelToken: Optional CancelToken to allow cancelling the request externally.
  • onReceiveProgress: Optional callback for tracking download progress.
  • cacheOptions: Optional CacheOptions 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,
    );
  }
}