A Flutter package that provides an interceptor for Dio that automatically refreshes the token when it expires.
In this example there are two implementations of the interceptor, a simple one and one with Riverpod.
This example is related to my article on Medium: How to create a RefreshTokenInterceptor in Flutter (with Dio)
First, you need to install the dependencies:
flutter pub get
Then, choose a device and run the project:
flutter run
Inside the main.dart
file, you can see that you can choose between the two implementations of the interceptor.
void main() {
// runApp(const MyApp()); -> Simple implementation
runApp( // Riverpod implementation
const ProviderScope(
child: MyAppRiverpod(),
),
);
}
By default, the MyAppRiverpod
is being used, but you can change it to MyApp
to use the simple implementation.
Made with ❤️ by Dario Varriale