RetryPolicy class
Controls automatic re-attempts of a failed request.
The request is rebuilt on every attempt, so its onRequest interceptors run
again — that is what lets an interceptor refresh an expired token in
onError and have the replay pick up the new one.
Constructors
- RetryPolicy({int maxAttempts = 3, Duration initialDelay = const Duration(milliseconds: 300), double backoffFactor = 2.0, Duration maxDelay = const Duration(seconds: 10), double jitter = 0.2, RetryPredicate retryIf = retryTransientFailures})
-
const
Properties
- backoffFactor → double
-
Multiplier applied to the delay after each failed attempt.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialDelay → Duration
-
Delay before the second attempt; grows by backoffFactor thereafter.
final
- jitter → double
-
Fraction of random jitter (0..1) applied to each delay, so that clients
failing together do not retry in lockstep.
final
- maxAttempts → int
-
Total attempts including the first.
1disables retrying.final - maxDelay → Duration
-
Upper bound on any single delay.
final
- retryIf → RetryPredicate
-
Whether a given failure should be retried.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
delayFor(
int attempt) → Duration -
Delay to wait before attempt number
attempt(1-based; the delay before the second attempt isdelayFor(1)). -
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
Static Methods
-
retryTransientFailures(
ApiResponse response, int attempt) → bool - Default predicate: retry transport failures, timeouts and 5xx responses, but only for methods that are safe to repeat.
Constants
- none → const RetryPolicy
- A policy that never retries.