Search packages, repositories and app categories

Package detailsv7.0.1

dio_smart_retry

Retry library for Dio and Dio package made with love. By default, the request will be retried only for appropriate retryable http statuses.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
209K
Likes
314
Pub points
145

Install package

flutter pub add dio_smart_retry

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

Dio Smart Retry is a retry utility for the Dio HTTP client, designed to automatically retry requests based on predefined conditions. It defaults to retrying only for HTTP status codes considered retryable, such as 5xx server errors or network timeouts. Built with simplicity and reliability in mind, it integrates seamlessly with existing Dio setups. The package supports all major platforms including Android, iOS, Web, macOS, Windows, and Linux, making it ideal for robust network operations in cross-platform Flutter apps.

Use cases

  • Handling transient network failures
  • Automating retries for server errors
  • Improving app resilience during poor connectivity
  • Simplifying error handling in API calls
  • Reducing manual retry logic in business code

Key features

  • Automatic retry for retryable HTTP statuses
  • Easy integration with Dio
  • Supports multiple platforms
  • Configurable retry behavior
  • Lightweight and minimal overhead

Suitable for

  • Flutter apps with frequent API calls
  • Apps requiring reliable network communication
  • Developers seeking simple retry logic
  • Projects using Dio for HTTP requests
  • Teams wanting to reduce boilerplate error handling

Considerations

  • Does not retry by default for client errors (4xx)
  • Custom retry logic requires additional configuration
  • Limited to Dio-based HTTP clients
  • May need tuning for high-latency environments
  • No built-in backoff strategy beyond basic retry

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Pub Version Dart SDK Version style: very good analysis License

Dio Smart Retry

Flexible retry library for Dio package. This is a next generation of an abandoned dio_retry package.
By default, the request will be retried only for appropriate retryable http statuses.
Also, it supports dynamic delay between retries.
Null Safety.

Contents

Getting Started for Dio

  1. Add package to pubspec.yaml: dio_smart_retry: ^7.0.0 **
  2. Import package: import 'package:dio_smart_retry/dio_smart_retry.dart'

** For the old dio (ver. 4.+) use dio_smart_retry: ^1.4.0

Usage

Just add an interceptor to your dio:

final dio = Dio();
// Add the interceptor
dio.interceptors.add(RetryInterceptor(
  dio: dio,
  logPrint: print, // specify log function (optional)
  retries: 3, // retry count (optional)
  retryDelays: const [ // set delays between retries (optional)
    Duration(seconds: 1), // wait 1 sec before first retry
    Duration(seconds: 2), // wait 2 sec before second retry
    Duration(seconds: 3), // wait 3 sec before third retry
  ],
));

/// Sending a failing request for 3 times with 1s, then 2s, then 3s interval
await dio.get('https://mock.codes/500');

See example/dio_smart_retry_example.dart.

Default retryable status codes list

Responses with these http status codes will be retried by default:

  • 408: RequestTimeout
  • 429: TooManyRequests
  • 500: InternalServerError
  • 502: BadGateway
  • 503: ServiceUnavailable
  • 504: GatewayTimeout
  • 440: LoginTimeout (IIS)
  • 460: ClientClosedRequest (AWS Elastic Load Balancer)
  • 499: ClientClosedRequest (ngnix)
  • 520: WebServerReturnedUnknownError
  • 521: WebServerIsDown
  • 522: ConnectionTimedOut
  • 523: OriginIsUnreachable
  • 524: TimeoutOccurred
  • 525: SSLHandshakeFailed
  • 527: RailgunError
  • 598: NetworkReadTimeoutError
  • 599: NetworkConnectTimeoutError It's possible to override this list

Disable retry

It's possible to manually disable retry for a specified request. Use disableRetry extension for that:

final request = RequestOptions(path: '/')
  ..disableRetry = true;
await dio.fetch<String>(request);

or

final options = Options()
  ..disableRetry = true;
await dio.get<String>('/', options: options);

Add extra retryable status codes

It's possible to add you own retryable status codes. Use retryableExtraStatuses parameter for that. Here is an example:

RetryInterceptor(
  dio: dio,
  retryableExtraStatuses: { status401Unauthorized },
)

or:

RetryInterceptor(
  dio: dio,
  retryableExtraStatuses: { 401 },
)

Override retryable statuses

It's possible to override default retryable status codes list. Just make new instance of DefaultRetryEvaluator and pass your status codes there.
Here is an example:

final myStatuses = { status400BadRequest, status409Conflict };
dio.interceptors.add(
  RetryInterceptor(
    dio: dio,
    logPrint: print,
    retryEvaluator: DefaultRetryEvaluator(myStatuses).evaluate,
  ),
);

await dio.get<dynamic>('https://mock.codes/400');

Migrating to 7.0

Use MultipartFile instead of MultipartFileRecreatable.

Categories

Dependencies

Dependency list 3 items

Source repository

Projects using this package