sm_network library

This is a network request library

Classes

BackgroundTransformer
The default Transformer for Dio.
BaseOptions
A set of base settings for each Dio(). BaseOptions and Options will be merged into one RequestOptions before sending the requests. See Options.compose.
BaseResp<T>
基础模型
BoolConverter
bool 转换器
CancelToken
Controls cancellation of Dio's requests.
Converter<R extends BaseResp<T>, T>
数据处理器
ConverterOptions
转换选项
DateDayConverter
日-日期时间 转换
DateHourConverter
时-日期时间 转换
DateMicroEpochConverter
微秒-日期时间 转换
DateMilliEpochConverter
毫秒-日期时间 转换
DateMinuteConverter
分-日期时间 转换
DateMonthConverter
月-日期时间 转换
DateSecondConverter
秒-日期时间 转换
DateStringConverter
日期格式化字符串-日期时间 转换
DateYearConverter
日-日期时间 转换
DefaultConverter<R extends BaseResp<T>, T>
默认数据转换
DefaultConverterOptions
默认选项
Dio
Dio enables you to make HTTP requests easily.
DioMixin
DoubleConverter
double 转换
ErrorInterceptorHandler
The handler for interceptors to handle error occurred during the request.
FormData
A class to create readable "multipart/form-data" streams. It can be used to submit forms and file uploads to http server.
FusedTransformer
A Transformer that has a fast path for decoding UTF8-encoded JSON. If the response is utf8-encoded JSON and no custom decoder is specified in the RequestOptions, this transformer is significantly faster than the default SyncTransformer and the BackgroundTransformer. This improvement is achieved by using a fused Utf8Decoder and JsonDecoder to decode the response, which is faster than decoding the utf8-encoded JSON in two separate steps, since Dart uses a special fast decoder for this case. See https://github.com/dart-lang/sdk/blob/5b2ea0c7a227d91c691d2ff8cbbeb5f7f86afdb9/sdk/lib/_internal/vm/lib/convert_patch.dart#L40
Headers
The headers class for requests and responses.
Http
http
HttpBaseOptions<R extends BaseResp<T>, T>
基础配置
HttpClientAdapter
HttpAdapter is a bridge between Dio and HttpClient.
HttpErrorCode
错误码
HttpLog
网络打印信息
HttpLogInterceptor
日志拦截器
HttpOptions<R extends BaseResp<T>, T>
请求配置
HttpRetryOptions
网络请求重试选项
IntConverter
int 转换
Interceptor
Interceptor helps to deal with RequestOptions, Response, and DioException during the lifecycle of a request before it reaches users.
Interceptors
A Queue-Model list for Interceptors.
InterceptorsWrapper
A helper class to create interceptors in ease.
JsonConverter<T, S>
Implement this class to provide custom converters for a specific Type.
JsonEnum
Allows configuration of how enum elements are treated as JSON.
JsonKey
An annotation used to specify how a field is serialized.
JsonLiteral
An annotation used to generate a private field containing the contents of a JSON file.
JsonSerializable
An annotation used to specify a class to generate code for.
JsonValue
An annotation used to specify how a enum value is serialized.
ListParam<T>
Indicates a param being used as queries or form data, and how does it gets formatted.
LogCatchOptions
错误拦截打印
LogInterceptor
LogInterceptor is used to print logs during network requests. It should be the last interceptor added, otherwise modifications by following interceptors will not be logged. This is because the execution of interceptors is in the order of addition.
LogOptions
打印配置
MultipartFile
An upload content that is a part of MultipartRequest. This doesn't need to correspond to a physical file.
NumConverter
num 转换
Options
The configuration for a single request. BaseOptions and Options will be merged into one RequestOptions before sending the requests. See Options.compose.
QueuedInterceptor
Interceptor in queue.
QueuedInterceptorsWrapper
A helper class to create QueuedInterceptor in ease.
RawSession<R extends BaseResp<T>, T>
原始请求会话
RedirectRecord
A record that records the redirection happens during requests, including status code, request method, and the location.
RequestInterceptorHandler
The handler for interceptors to handle before the request has been sent.
RequestMethod<R extends BaseResp<T>, T>
请求接口
RequestOptions
The internal request option class that is the eventual result after BaseOptions and Options are composed.
Response<T>
The Response class contains the payload (could be transformed) that respond from the request, and other information of the response.
ResponseBody
The response wrapper class for adapters.
ResponseInterceptorHandler
The handler for interceptors to handle after respond.
RetryOptions
Object holding options for retrying a function.
SecondDurationConverter
时间转换
Session<T>
请求会话
StringConverter
int 转换
SyncTransformer
If you want to custom the transformation of request/response data, you can provide a Transformer by your self, and replace the transformer by setting the Dio.transformer.
Transformer
Transformer allows changes to the request/response data before it is sent/received to/from the server.

Enums

ContentType
请求体
DioExceptionType
The exception enumeration indicates what type of exception has happened during requests.
FieldRename
Values for the automatic field renaming behavior for JsonSerializable.
FileAccessMode
The file access mode when downloading a file, corresponds to a subset of dart:io::FileMode.
ListFormat
Specifies the array format (a single parameter with multiple parameter or multiple parameters with the same name). and the separator for array items.
Method
请求方法, dio 内部会转成大写
ResponseType
Indicates which transformation should be applied to the response data.

Mixins

HttpOptionsMixin<R extends BaseResp<T>, T>
参数混入
OptionsMixin
The mixin class for options that provides common attributes.
RequestMixin<R extends BaseResp<T>, T>
请求混入

Functions

$checkedConvert<T>(Map map, String key, T castFunc(dynamic), {Object? readValue(Map, String)?}) → T
Helper function used in generated code when JsonSerializableGenerator.checked is true.
$checkedCreate<T>(String className, Map map, T constructor(S <S>(String, S (Object?), {Object? readValue(Map, String)?})), {Map<String, String> fieldKeyMap = const {}}) → T
Helper function used in generated code when JsonSerializableGenerator.checked is true.
$checkedNew<T>(String className, Map map, T constructor(), {Map<String, String>? fieldKeyMap}) → T
Helper function used in generated code when JsonSerializableGenerator.checked is true.
$checkKeys(Map map, {List<String>? allowedKeys, List<String>? requiredKeys, List<String>? disallowNullValues}) → void
Helper function used in generated fromJson code when JsonSerializable.disallowUnrecognizedKeys is true for an annotated type or JsonKey.required is true for any annotated fields.
$enumDecode<K extends Enum, V>(Map<K, V> enumValues, Object? source, {K? unknownValue}) → K
Returns the key associated with value source from enumValues, if one exists.
$enumDecodeNullable<K extends Enum, V>(Map<K, V> enumValues, Object? source, {Enum? unknownValue}) → K?
Returns the key associated with value source from enumValues, if one exists.
defaultDioExceptionReadableStringBuilder(DioException e) String
The default implementation of building a readable string of DioException.
retry<T>(FutureOr<T> fn(), {Duration delayFactor = const Duration(milliseconds: 200), double randomizationFactor = 0.25, Duration maxDelay = const Duration(seconds: 30), int maxAttempts = 8, RetryFunction<bool>? retryIf, RetryFunction<void>? onRetry}) Future<T>
Call fn retrying so long as retryIf return true for the exception thrown, up-to maxAttempts times.

Typedefs

DefaultTransformer = SyncTransformer
DioError = DioException
DioError describes the exception info when a request failed.
DioErrorType = DioExceptionType
Deprecated in favor of DioExceptionType and will be removed in future major versions.
DioExceptionReadableStringBuilder = String Function(DioException e)
The readable string builder's signature of DioException.readableStringBuilder.
DioMediaType = MediaType
The type (alias) for specifying the content-type of the MultipartFile.
FormFiles = Map<String, MultipartFile>
表单文件
FromJsonT<T> = T Function(Parameters)
json 数据转换
HeaderForEachCallback = void Function(String name, List<String> values)
The signature that iterates header fields.
HttpDebugLog = void Function(Object object)
打印调试信息
HttpErrorLog = void Function(Object error, StackTrace? stackTrace)
打印错误信息
HTTPHeaders = Parameters
请求头
InterceptorErrorCallback = void Function(DioException error, ErrorInterceptorHandler handler)
The signature of Interceptor.onError.
InterceptorSendCallback = void Function(RequestOptions options, RequestInterceptorHandler handler)
The signature of Interceptor.onRequest.
InterceptorSuccessCallback = void Function(Response response, ResponseInterceptorHandler handler)
The signature of Interceptor.onResponse.
JsonDecodeCallback = FutureOr Function(String)
The callback definition for decoding a JSON string.
JsonEncodeCallback = FutureOr<String> Function(Object)
The callback definition for encoding a JSON object.
Parameters = Map<String, dynamic>
参数
ProgressCallback = void Function(int count, int total)
The type of a progress listening callback when sending or receiving data.
RequestEncoder = FutureOr<List<int>> Function(String request, RequestOptions options)
The type of a request encoding callback.
ResponseDecoder = FutureOr<String?> Function(List<int> responseBytes, RequestOptions options, ResponseBody responseBody)
The type of a response decoding callback.
RetryFunction<T> = FutureOr<T> Function(Exception e, int attempt)
A function that returns T if the function should be retried.
ValidateStatus = bool Function(int? status)
The type of a response status code validate callback.
ValidateT = bool Function(int? status, Parameters data)
验证状态

Exceptions / Errors

BadKeyException
A base class for exceptions thrown when decoding JSON.
CheckedFromJsonException
Exception thrown if there is a runtime exception in fromJson code generated when JsonSerializableGenerator.checked is true
DioException
DioException describes the exception info when a request failed.
DisallowedNullValueException
Exception thrown if there are keys with disallowed null values in a JSON map that was provided during deserialization.
HttpError
网络错误
MissingRequiredKeysException
Exception thrown if there are missing required keys in a JSON map that was provided during deserialization.
NotNullableError<T>
A TypeError thrown by _checkNotNullable.
UnrecognizedKeysException
Exception thrown if there are unrecognized keys in a JSON map that was provided during deserialization.