dio_retry_plus 0.0.7 dio_retry_plus: ^0.0.7 copied to clipboard
A plugin for dio that retries failed requests.
dio_retry_plus #
A plugin for dio that retries failed requests.
Usage #
import 'package:dio_retry_plus/dio_retry_plus.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.