retry_bot 1.0.1 retry_bot: ^1.0.1 copied to clipboard
Dio interceptor Retry which makes retrying API Call When getting a timeout.
🤖 Retry Bot #
Performing HTTP requests is all fun and games until there's no internet connection. Sure, you can display a sad error message or a "Chrome dinosaur" to the user, but wouldn't it be better to take the initiative and automatically retry the request when the user connects to a WiFi network or enables mobile data? This is precisely what we're going to introduce with ** Retry Bot**
Usage #
Add a dependency in your pubspec. yaml
:
dependencies:
retry_bot: ^1.0.1
Simple usage using Retry Bot
:
- First: Create a new instance from Dio
import 'package:dio/dio.dart';
final dio = Dio();
- Second: Create a new instance from Connectivity
import 'package:connectivity_plus/connectivity_plus.dart';
final connectivity = Connectivity();
- Third: Create a new instance from DioConnectivityRequest and pass dio and connectivity objects as params
import 'package:retry_bot/retry_bot.dart';
final request = DioConnectivityRequest(
connectivity: connectivity,
dio: dio,
);
- Fourth: Create a new instance from OnRetryConnection and pass requests as params
import 'package:retry_bot/retry_bot.dart';
final retryInterceptor = OnRetryConnection(
request: request,
);
- Finally: Add your OnRetryConnection object to Dio Interceptors
import 'package:retry_bot/retry_bot.dart';
dio.interceptors.add(retryInterceptor);
Simple Usage #
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dio/dio.dart';
import 'package:retry_bot/retry_bot.dart';
void main() {
final dio = Dio();
final connectivity = Connectivity();
final request = DioConnectivityRequest(
connectivity: connectivity,
dio: dio,
);
final retryInterceptor = OnRetryConnection(
request: request,
);
dio.interceptors.add(retryInterceptor);
}