RetryPolicy class

Defines how failed requests should be retried.

final policy = RetryPolicy(
  maxRetries: 3,
  backoff: ExponentialBackoff(baseDelay: Duration(seconds: 1)),
);
Annotations

Constructors

RetryPolicy({int maxRetries = 3, BackoffStrategy backoff = const ExponentialBackoff(), bool shouldRetry(Object error, int attempt)?})
Creates a RetryPolicy.
const

Properties

backoff BackoffStrategy
Back-off strategy.
final
hashCode int
The hash code for this object.
no setterinherited
maxRetries int
Maximum number of retries.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shouldRetry bool Function(Object error, int attempt)?
Optional predicate. When null, every error is retried.
final

Methods

canRetry(int attempt) bool
Whether attempt (0-indexed) is within the allowed retry count.
delayFor(int attempt) Duration
Returns the delay to wait before the given attempt (0-indexed).
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

Constants

defaultPolicy → const RetryPolicy
Default policy: 3 retries with exponential back-off starting at 1 s.
none → const RetryPolicy
No-retry policy.