DioClient class abstract
An abstract base class for making network requests using the Dio package.
Provides standardized methods for common HTTP verbs (GET, POST, PUT, DELETE)
and specialized methods like fetch (for raw bytes) and download (to file).
Includes built-in error handling that converts DioException
s into custom
NetworkExceptions, and integrates with dio_cache_interceptor
for caching
(except for download).
Extend this class to create concrete API client implementations.
Error Handling:
All request methods catch DioException
and translate them into specific
NetworkException subtypes based on the error type and response status.
Unexpected non-Dio errors are wrapped in UnknownNetworkErrorException.
Caching:
Caching behavior can be controlled globally via globalCacheOptions passed
to the constructor, or per-request via the cacheOptions
parameter on
methods like get, post, put, delete, and fetch. The download
method does not support caching.
Retry Logic:
This client does not implement automatic retry logic. Retries should be
handled externally, preferably by adding a retry interceptor (e.g., from
the dio_smart_retry
package) to the Dio
instance before passing it
to this client's constructor.
Constructors
-
DioClient.new({required Dio dioClient, CacheOptions? globalCacheOptions, Iterable<
Interceptor> ? interceptors, HttpClientAdapter? httpClientAdapter}) - Creates an instance of DioClient.
Properties
- globalCacheOptions → CacheOptions?
-
Optional global cache options applied to requests if specific
cacheOptions
are not provided for a particular request.final - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
delete(
String url, {dynamic data, Map< String, dynamic> ? queryParameters, Options? options, CancelToken? cancelToken, CacheOptions? cacheOptions}) → Future<Response> -
Sends a DELETE request to the specified
url
. -
download(
String url, String savePath, {Map< String, dynamic> ? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, bool deleteOnError = true}) → Future<Response> -
Downloads a file from the specified
url
and saves it tosavePath
. -
fetch(
String url, {Map< String, dynamic> ? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, CacheOptions? cacheOptions}) → Future<Response< List< >int> > -
Fetches raw data from the specified
url
as a list of bytes. -
get(
String url, {Map< String, dynamic> ? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, CacheOptions? cacheOptions}) → Future<Response> -
Sends a GET request to the specified
url
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
post(
String url, {dynamic data, Map< String, dynamic> ? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress, CacheOptions? cacheOptions}) → Future<Response> -
Sends a POST request to the specified
url
. -
put(
String url, {dynamic data, Map< String, dynamic> ? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress, CacheOptions? cacheOptions}) → Future<Response> -
Sends a PUT request to the specified
url
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited