RetryPolicy class
A standardized retry policy for consistent retry behavior across features.
Provides helper methods for cubits to standardize retry behavior (search, chat, charts, etc.) with cancellation support.
When a RetryDelay is passed to executeWithRetry, backoff waits use it (testable / app-adapted delays). When null, uses Future.delayed.
Constructors
- RetryPolicy({int maxAttempts = 3, Duration baseDelay = const Duration(seconds: 1), Duration maxDelay = const Duration(seconds: 30), RetryStrategy strategy = RetryStrategy.exponential, bool jitter = true, bool shouldRetry(Object error)?})
-
Creates a retry policy with the specified configuration.
const
Properties
- baseDelay → Duration
-
Base delay between retries.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- jitter → bool
-
Whether to add random jitter to delays (helps prevent thundering herd).
final
- maxAttempts → int
-
Maximum number of retry attempts (including initial attempt).
final
- maxDelay → Duration
-
Maximum delay cap for exponential/linear backoff.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shouldRetry → bool Function(Object error)?
-
Default error filter for this policy. Per-call executeWithRetry override
wins when provided.
final
- strategy → RetryStrategy
-
Retry strategy to use for calculating delays.
final
Methods
-
executeWithRetry<
T> ({required Future< T> action(), CancelToken? cancelToken, bool shouldRetry(Object error)?, RetryDelay? delay}) → Future<T> - Execute an action with retry logic.
-
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
-
calculateDelay(
{required int attempt, required Duration baseDelay, required Duration maxDelay, RetryStrategy strategy = RetryStrategy.exponential, bool jitter = true}) → Duration - Shared delay calculation for use by other layers (e.g. HTTP client).
-
isTransientError(
Object error) → bool - Conservative classifier used by transientErrors / networkErrors.
Constants
- networkErrors → const RetryPolicy
- Create a retry policy for network-style timeouts with longer delays.
- transientErrors → const RetryPolicy
- Create a default retry policy for transient errors (timeouts).