RetryConfig class
重试配置
Constructors
-
RetryConfig({required RetryStrategy strategy, int maxAttempts = 3, Duration? initialDelay, Duration? maxDelay, bool enableJitter = true, double jitterFactor = 0.2, List<
int> ? retryableStatusCodes, void onRetry(int attemptNumber, DioException error, Duration delay)?, bool retryOnlyNetworkErrors = false})
Properties
- enableJitter → bool
-
是否启用抖动(jitter),避免重试风暴
抖动会在计算的延迟基础上添加随机偏移
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialDelay → Duration?
-
初始延迟
final
- jitterFactor → double
-
抖动因子(0.0 - 1.0),默认0.2表示±20%的随机偏移
final
- maxAttempts → int
-
最大重试次数
final
- maxDelay → Duration?
-
最大延迟
final
- onRetry → void Function(int attemptNumber, DioException error, Duration delay)?
-
重试回调函数
在每次重试前调用,可用于通知UI层或记录日志
attemptNumber当前重试次数(从1开始)error导致重试的错误delay即将等待的延迟时间final -
retryableStatusCodes
→ List<
int> -
可重试的HTTP状态码
默认包含:408(请求超时)、429(太多请求)、500(服务器错误)、
502(网关错误)、503(服务不可用)、504(网关超时)
final
- retryOnlyNetworkErrors → bool
-
是否只在网络错误时重试(不包括HTTP错误)
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- strategy → RetryStrategy
-
重试策略
final
Methods
-
calculateDelay(
int attemptNumber) → Duration - 计算重试延迟(包含抖动)
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
shouldRetry(
DioException error, int attemptNumber) → bool - 判断是否应该重试
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
aggressive(
) → RetryConfig - 预定义配置:激进重试(快速重试,适合瞬时故障)
-
conservative(
) → RetryConfig - 预定义配置:保守重试(较长延迟,适合服务器过载)
-
networkOnly(
) → RetryConfig - 预定义配置:仅网络错误重试