dio_retry 0.1.9-beta

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

dio_retry #

A plugin for dio that retries failed requests.

Usage #

import 'package:dio_retry/dio_retry.dart';

Basic configuration #

final dio = Dio()

Global retry options #

final dio = Dio()
    options: const RetryOptions(
      retries: 3, // Number of retries before a failure
      retryInterval: const Duration(seconds: 1), // Interval between each retry
      retryEvaluator: (error) => error.type != DioErrorType.CANCEL && error.type != DioErrorType.RESPONSE, // Evaluating if a retry is necessary regarding the error. It is a good candidate for updating authentication token in case of a unauthorized error (be careful with concurrency though)

Sending a request with options #

final response = await dio.get("http://www.flutter.dev", options: Options(
    extra: RetryOptions(
      retryInterval: const Duration(seconds: 10),

Sending a request without retry #

final response = await dio.get("http://www.flutter.dev", options: Options(
    extra: RetryOptions.noRetry().toExtra(),

Logging retry operations #

final dio = Dio()
  ..interceptors.add(RetryInterceptor(logger: Logger("Retry")));

Features and bugs #

Please file issues.

0.1.9-beta #

  • Support Dio 3 which works on Flutter web

0.1.8-beta #

  • Initial version, created by Stagehand


import 'package:dio/dio.dart';
import 'package:dio_retry/dio_retry.dart';
import 'package:logging/logging.dart';

main() async {
  // Displaying logs
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((record) {
    print('${record.level.name}: ${record.time}: ${record.message}');

  final dio = Dio();

  // Add the interceptor with optional options
    dio: dio,
    logger: Logger("Retry"),
    options: const RetryOptions(
      retryInterval: const Duration(seconds: 5),

  /// Sending a failing request for 3 times with a 5s interval
  try {
    await dio.get("http://www.mqldkfjmdisljfmlksqdjfmlkj.dev");
  } catch (e) {
    print("End error : $e");

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dio_retry: ^0.1.9-beta

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:dio_retry/dio_retry.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Format lib/dio_retry.dart.

Run dartfmt to format lib/dio_retry.dart.

Format lib/src/options.dart.

Run dartfmt to format lib/src/options.dart.

Maintenance suggestions

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can change in breaking ways.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
dio ^3.0.0 3.0.8
logging ^0.11.3 0.11.4
meta ^1.1.6 1.1.8
Transitive dependencies
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
path 1.6.4
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.0.0
test ^1.0.0