Dio class abstract

A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, File downloading etc. and Dio is very easy to use.

You can create a dio instance and config it by two ways:

  1. create first , then config it
 var dio = Dio();
 dio.options.baseUrl = "http://www.dtworkroom.com/doris/1/2.0.0/";
 dio.options.connectTimeout = 5000; //5s
 dio.options.receiveTimeout = 5000;
 dio.options.headers = {HttpHeaders.userAgentHeader: 'dio', 'common-header': 'xx'};
  1. create and config it:
  var dio = Dio(BaseOptions(
   baseUrl: "http://www.dtworkroom.com/doris/1/2.0.0/",
   connectTimeout: 5000,
   receiveTimeout: 5000,
   headers: {HttpHeaders.userAgentHeader: 'dio', 'common-header': 'xx'},
  ));

Constructors

Dio([BaseOptions? options])
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
httpClientAdapter HttpClientAdapter
getter/setter pair
interceptors Interceptors
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 request methods 'PUT', 'POST', and 'PATCH'.
getter/setter pair

Methods

clear() → void
Clear the current Dio instance waiting queue.
close({bool force = false}) → void
Shuts down the dio client.
delete<T>(String path, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken}) Future<Response<T>>
Handy method to make http DELETE request, which is a alias of dio.fetch(RequestOptions).
deleteUri<T>(Uri uri, {dynamic data, Options? options, CancelToken? cancelToken}) Future<Response<T>>
Handy method to make http DELETE request, which is a alias of dio.fetch(RequestOptions).
download(String urlPath, dynamic savePath, {ProgressCallback? onReceiveProgress, Map<String, dynamic>? queryParameters, CancelToken? cancelToken, bool deleteOnError = true, String lengthHeader = Headers.contentLengthHeader, dynamic 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, dynamic 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>>
get<T>(String path, {Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Handy method to make http GET request, which is a alias of dio.fetch(RequestOptions).
getUri<T>(Uri uri, {Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Handy method to make http GET request, which is a alias of dio.fetch(RequestOptions).
Handy method to make http HEAD request, which is a alias of dio.fetch(RequestOptions).
headUri<T>(Uri uri, {dynamic data, Options? options, CancelToken? cancelToken}) Future<Response<T>>
Handy method to make http HEAD request, which is a alias of dio.fetch(RequestOptions).
lock() → void
Lock the current Dio instance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch<T>(String path, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Handy method to make http PATCH request, which is a alias of dio.fetch(RequestOptions).
patchUri<T>(Uri uri, {dynamic data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Handy method to make http PATCH request, which is a alias of dio.fetch(RequestOptions).
post<T>(String path, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Handy method to make http POST request, which is a alias of dio.fetch(RequestOptions).
postUri<T>(Uri uri, {dynamic data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Handy method to make http POST request, which is a alias of dio.fetch(RequestOptions).
put<T>(String path, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Handy method to make http PUT request, which is a alias of dio.fetch(RequestOptions).
putUri<T>(Uri uri, {dynamic data, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Handy method to make http PUT request, which is a alias of dio.fetch(RequestOptions).
request<T>(String path, {dynamic 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, {dynamic data, CancelToken? cancelToken, Options? options, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress}) Future<Response<T>>
Make http request with options.
toString() String
A string representation of this object.
inherited
unlock() → void
Unlock the current Dio instance.

Operators

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