defaultRetry static method

Duration? defaultRetry(
  1. int retryCount,
  2. Object error, {
  3. int maxRetries = 10,
  4. Duration maxDelay = const Duration(milliseconds: 6400),
  5. Duration minDelay = const Duration(milliseconds: 200),
})

The default implementation of retry.

The function takes two parameters:

  • retryCount: The number of times the provider has been retried (starting at 0).
  • error: The error that caused the retry.

The function takes two parameters:

  • retryCount: The number of times the provider has been retried (starting at 0).
  • error: The error that caused the retry.

The default implementation:

  • 10 retries
  • starts with a delay of 200ms
  • doubles the delay on each retry up to 6.4 seconds
  • retries all failures
  • ignores ProviderExceptions (which happens when a provider rethrows the error of another provider)
  • ignores Errors (which are generally programming errors)

To learn more about retry logic, see Automatic Retry.

Implementation

static Duration? defaultRetry(
  int retryCount,
  Object error, {
  int maxRetries = 10,
  Duration maxDelay = const Duration(milliseconds: 6400),
  Duration minDelay = const Duration(milliseconds: 200),
}) {
  if (retryCount >= maxRetries) return null;
  if (error is ProviderException || error is Error) return null;

  final delay = minDelay * math.pow(2, retryCount).toInt();
  if (delay > maxDelay) return maxDelay;

  return delay;
}