Dio class abstract

Dio enables you to make HTTP requests easily.

Creating a Dio instance with configurations:

final dio = Dio(
  BaseOptions(
    baseUrl: "https://pub.dev",
    connectTimeout: const Duration(seconds: 5),
    receiveTimeout: const Duration(seconds: 5),
    headers: {
      HttpHeaders.userAgentHeader: 'dio',
      'common-header': 'xx',
    },
  )
);

The Dio.options can be updated in anytime:

dio.options.baseUrl = "https://pub.dev";
dio.options.connectTimeout = const Duration(seconds: 5);
dio.options.receiveTimeout = const Duration(seconds: 5);
Implementers

Constructors

Dio([BaseOptions? options])
Create the default Dio instance with the default implementation based on different platforms.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
httpClientAdapter HttpClientAdapter
The adapter that the instance is using.
getter/setter pair
interceptors Interceptors
Return the interceptors added into the instance.
no setter
options BaseOptions
Default Request config. More see BaseOptions .
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
transformer Transformer
Transformer allows changes to the request/response data before it is sent/received to/from the server. This is only applicable for requests that have payload.
getter/setter pair

Methods

close({bool force = false}) → void
Shuts down the dio client.
delete<T>(String path, {Object? data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken}) Future<Response<T>>
Convenience method to make an HTTP DELETE request.
deleteUri<T>(Uri uri, {Object? data, Options? options, CancelToken? cancelToken}) Future<Response<T>>
Convenience method to make an HTTP DELETE request with Uri.
download(String urlPath, dynamic savePath, {ProgressCallback? onReceiveProgress, Map<String, dynamic>? queryParameters, CancelToken? cancelToken, bool deleteOnError = true, String lengthHeader = Headers.contentLengthHeader, Object? data, Options? options}) Future<Response>
Download the file and save it in local. The default http method is "GET", you can custom it by Options.method.
downloadUri(Uri uri, dynamic savePath, {ProgressCallback? onReceiveProgress, CancelToken? cancelToken, bool deleteOnError = true, String lengthHeader = Headers.contentLengthHeader, Object? data, Options? options}) Future<Response>
Download the file and save it in local. The default http method is "GET", you can custom it by Options.method.
fetch<T>(RequestOptions requestOptions) Future<Response<T>>
The eventual method to submit requests. All callers for requests should eventually go through this method.
get<T>(String path, {Object? data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Convenience method to make an HTTP GET request.
getUri<T>(Uri uri, {Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Convenience method to make an HTTP GET request with Uri.
Convenience method to make an HTTP HEAD request.
headUri<T>(Uri uri, {Object? data, Options? options, CancelToken? cancelToken}) Future<Response<T>>
Convenience method to make an HTTP HEAD request with Uri.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch<T>(String path, {Object? data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Convenience method to make an HTTP PATCH request.
patchUri<T>(Uri uri, {Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Convenience method to make an HTTP PATCH request with Uri.
post<T>(String path, {Object? data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Convenience method to make an HTTP POST request.
postUri<T>(Uri uri, {Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Convenience method to make an HTTP POST request with Uri.
put<T>(String path, {Object? data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Convenience method to make an HTTP PUT request.
putUri<T>(Uri uri, {Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Convenience method to make an HTTP PUT request with Uri.
request<T>(String url, {Object? data, Map<String, dynamic>? queryParameters, CancelToken? cancelToken, Options? options, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Make HTTP request with options.
requestUri<T>(Uri uri, {Object? data, CancelToken? cancelToken, Options? options, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Make http request with options with Uri.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited