flutter-dio
Original:🇺🇸 English
Translated
HTTP Networking with Dio, Retry & Caching Patterns
3installs
Sourcedhruvanbhalara/skills
Added on
NPX Install
npx skill4agent add dhruvanbhalara/skills flutter-dioTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Networking with Dio
- Use Dio as the primary HTTP client package.
- Use type-safe model classes with /
fromJsonfactories for all request/response bodies.toJson - Handle all HTTP status codes appropriately with typed exceptions (e.g., ,
ServerException,NetworkException).UnauthorizedException - Use proper request timeouts (,
connectTimeout,receiveTimeout).sendTimeout
Dio Interceptors
- Use interceptors for cross-cutting concerns:
- Auth Interceptor: Attach access tokens to headers, handle token refresh on 401.
- Logging Interceptor: Log requests/responses in debug mode via .
AppLogger - Error Interceptor: Transform into domain-specific
DioExceptiontypes.Failure
- Register interceptors centrally via for consistent behavior across all API calls.
injectable
Repository Pattern
- DataSources contain only raw Dio API calls — no business logic or mapping
- Repositories orchestrate between remote DataSources and local cache for network data
Retry & Resilience
- Implement retry logic with exponential backoff for transient failures (e.g., 500, timeout).
- Set a maximum retry count (default: 3 retries).
- Cache responses when appropriate to reduce network calls and improve offline UX.
Performance
- Parse JSON in background isolates for large responses (> 1MB) using
compute() - Do NOT block the UI thread with synchronous network operations
Security
- Store tokens via — never in source code or
flutter_secure_storageSharedPreferences - All API communication MUST use HTTPS