dio_retry_fixed 0.1.12-beta copy "dio_retry_fixed: ^0.1.12-beta" to clipboard
dio_retry_fixed: ^0.1.12-beta copied to clipboard

outdated

A patched version of dio_retry

dio_retry #

A plugin for dio that retries failed requests.

Usage #

import 'package:dio_retry/dio_retry.dart';

Basic configuration

final dio = Dio()
  ..interceptors.add(RetryInterceptor());

Global retry options

final dio = Dio()
  ..interceptors.add(RetryInterceptor(
    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),
    ).toExtra(),
  ));

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.