RetryOptions class
Configuration for automatic request retry with exponential backoff.
When enabled, failed requests are automatically retried with increasing delays between attempts. This helps handle transient network issues and server overload gracefully.
Example usage:
RetryOptions(
enabled: true,
maxRetries: 3,
initialDelay: Duration(milliseconds: 500),
retryableStatusCodes: [500, 502, 503, 504],
)
With default settings and backoffMultiplier of 2.0:
- 1st retry: 500ms delay
- 2nd retry: 1000ms delay
- 3rd retry: 2000ms delay
Constructors
-
RetryOptions({bool enabled = false, int maxRetries = 3, Duration initialDelay = const Duration(milliseconds: 500), Duration maxDelay = const Duration(seconds: 30), double backoffMultiplier = 2.0, List<
int> retryableStatusCodes = const [408, 429, 500, 502, 503, 504], bool retryOnConnectionError = true}) -
Creates retry options with the specified configuration.
const
Properties
- backoffMultiplier → double
-
Multiplier for exponential backoff (default: 2.0).
final
- enabled → bool
-
Whether automatic retry is enabled (default: false).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialDelay → Duration
-
Delay before the first retry attempt (default: 500ms).
final
- maxDelay → Duration
-
Maximum delay between retry attempts (default: 30 seconds).
final
- maxRetries → int
-
Maximum number of retry attempts (default: 3).
final
-
retryableStatusCodes
→ List<
int> -
HTTP status codes that trigger a retry.
final
- retryOnConnectionError → bool
-
Whether to retry on connection errors (default: true).
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getDelayForAttempt(
int attempt) → Duration - Calculates the delay for a given retry attempt using exponential backoff.
-
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