HttpConfig class
HTTP 工具类配置 用于配置请求头、错误处理等
Constructors
-
HttpConfig({required String baseUrl, ResponseParser? responseParser, Map<
String, String> ? staticHeaders, Future<Map< dynamicHeaderBuilder()?, String? networkErrorKey, VoidCallback? on401Unauthorized, void onFailure(int? httpStatusCode, int? errorCode, String message)?, Duration errorDeduplicationWindow = const Duration(seconds: 5), bool enableLogging = false, bool logPrintBody = true, LogMode logMode = LogMode.complete, bool logShowRequestHint = true, BuildContext? contextGetter()?, Widget loadingWidgetBuilder(BuildContext context)?, DeduplicationConfig? deduplicationConfig, QueueConfig? queueConfig, Map<String, String> >String, String> ? serviceBaseUrls, UnauthorizedRetryConfig? unauthorizedRetry, bool disableReceiveTimeout = false, Duration? connectTimeout, Duration? sendTimeout})
Properties
- baseUrl → String
-
基础 URL
final
- connectTimeout → Duration?
-
TCP 连接超时;
null表示交给 Dio 默认。final - contextGetter → BuildContext? Function()?
-
Context 获取器(可选)
如果提供,工具包会自动使用加载提示功能
final
- deduplicationConfig → DeduplicationConfig?
-
请求去重/防抖配置(可选)
如果提供,将启用请求去重/防抖功能
final
- disableReceiveTimeout → bool
-
为
true时,Dio 不设置接收超时(receiveTimeout: null),等待响应体不设上限。final -
dynamicHeaderBuilder
→ Future<
Map< Function()?String, String> > -
动态请求头构建器(每次请求时调用)
返回的 Map 会合并到请求头中
final
- enableLogging → bool
-
是否启用日志打印(默认 false)
启用后会自动打印请求和响应信息
final
- errorDeduplicationWindow → Duration
-
错误去重时间窗口(默认 5 秒)
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- loadingWidgetBuilder → Widget Function(BuildContext context)?
-
自定义加载提示 Widget 构建器(可选)
如果提供,将使用自定义的加载提示 UI
如果不提供,将使用工具包内置的默认实现
final
- logMode → LogMode
-
日志打印模式(默认 complete)
final
- logPrintBody → bool
-
日志打印级别
final
- logShowRequestHint → bool
-
是否在请求时显示简要提示(仅在 complete 模式下有效,默认 true)
如果为 true,请求时会打印一行简要信息,如 "→ POST /api/login"
final
- networkErrorKey → String?
-
网络错误提示消息的键(用于国际化)
如果为 null,则使用默认消息
final
-
401 未授权回调(专门处理 401 错误)
final
- onFailure → void Function(int? httpStatusCode, int? errorCode, String message)?
-
错误消息显示回调(全局默认错误处理)
如果为 null,则不显示错误提示
final
- queueConfig → QueueConfig?
-
请求队列配置(可选)
如果提供,将启用请求队列管理功能
final
- responseParser → ResponseParser
-
响应解析器(可选,默认使用 StandardResponseParser)
用于将原始 HTTP 响应(RawHttpResponse)转换为用户定义的 Response
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sendTimeout → Duration?
-
发送超时;
null表示交给 Dio 默认。final -
serviceBaseUrls
→ Map<
String, String> ? -
服务 baseUrl 映射(可选)
key: 服务名称(如 'files', 'cdn'),value: 对应的 baseUrl
final
-
staticHeaders
→ Map<
String, String> ? -
静态请求头(固定值)
final
-
会话过期时自动 UnauthorizedRetryConfig.refreshAccessToken 并重试(在
send内部完成,业务无感)。final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited