flutter_smart_retry library
Advanced retry logic for Flutter with exponential backoff, jitter, circuit breaker, and custom retry policies.
Features
- Multiple retry policies: Exponential, linear, fixed delay, and custom
- Circuit breaker: Prevent cascading failures
- Jitter: Randomized delays to prevent thundering herd
- Flexible configuration: Callbacks, timeouts, and custom logic
- Zero dependencies: Pure Dart implementation
Quick Start
import 'package:flutter_smart_retry/flutter_smart_retry.dart';
// Simple retry with exponential backoff
final result = await SmartRetry.execute(
() => apiCall(),
options: RetryOptions(
policy: ExponentialBackoffPolicy(
maxAttempts: 3,
baseDelay: Duration(seconds: 1),
),
),
);
With Circuit Breaker
final circuitBreaker = CircuitBreaker(
failureThreshold: 5,
resetTimeout: Duration(seconds: 60),
);
final result = await SmartRetry.execute(
() => apiCall(),
options: RetryOptions(
policy: ExponentialBackoffPolicy(),
circuitBreaker: circuitBreaker,
),
);
Classes
- CircuitBreaker
- Circuit breaker to prevent cascading failures.
- CustomRetryPolicy
- Custom retry policy with user-defined logic.
- ExponentialBackoffPolicy
- Exponential backoff retry policy.
- FixedDelayPolicy
- Fixed delay retry policy.
- LinearBackoffPolicy
- Linear backoff retry policy.
- RetryOptions
- Retry options for fine-tuning retry behavior.
- RetryPolicy
- Retry policy that defines how retries should be executed.
- SmartRetry
- Main retry executor.
Enums
- CircuitState
- Circuit breaker states.
Exceptions / Errors
- CircuitBreakerOpenException
- Exception thrown when circuit breaker is open.