HTTP client for Dart and Flutter with interceptors, FormData and cancellation
open sourceMITfree
dio is an HTTP client for Dart and Flutter. It adds what Dart's basic HTTP package leaves out: an instance with shared defaults (base URL, headers, timeouts), interceptors to change requests, responses and errors (including a queued interceptor for refreshing tokens), FormData and multi-file uploads with progress, downloads and streamed responses, cancellation tokens, transformers, proxy and certificate pinning settings, and swappable adapters. Plugins add a cookie manager, HTTP/2, the platform's native HTTP stack and a web adapter. It was started by wendux under flutterchina and has been maintained by the Chinese Flutter User Group since 2023.
Problems it solves
- refresh an expired auth token and retry the request in my Flutter app
- upload several files with a progress bar from Flutter
- set a base URL and default headers for every API call in my Dart app
- cancel an in-flight HTTP request when the user leaves the screen
- log every HTTP request and response my Flutter app makes
Features
- global defaults: base URL, headers, timeouts
- interceptors, including QueuedInterceptor and LogInterceptor
- FormData and multiple file uploads with progress
- file downloads and streamed responses
- request cancellation
- custom transformers
- proxy settings and HTTPS certificate verification
- swappable HttpClientAdapter
- plugins: cookie manager, HTTP/2, native adapter, web adapter
