Networking with Dio
SkillDev toolsUse when configuring HTTP network clients with Dio, adding auth token interceptors, handling retry logic, or caching API responses.
Use Networking with Dio in Claude, ChatGPT or Ahel Desktop
Free. Sign in, add Networking with Dio and connect your AI. About a minute.
Also: Claude Code · Cursor · Codex
Then ask your AI: use the Networking with Dio skill
Details
Instructions available. Your AI can read the instructions. Execution depends on the setup they require.
Account requirements not reviewed. Check the skill instructions before use; Ahel provides instructions and does not run this skill.
No other account needed.
Add Ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.
What this skill tells your AI
The instructions your AI receives, as published by dhruvanbhalara/skills in skills/flutter/flutter-dio/SKILL.md and read by Ahel’s review.
- Use Dio as the primary HTTP client package.
- Use type-safe model classes with
fromJson/toJsonfactories for all request/response bodies. - 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
DioExceptioninto domain-specificFailuretypes.
- Register interceptors centrally via
injectablefor consistent behavior across all API calls.
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
flutter_secure_storage: never in source code orSharedPreferences - All API communication MUST use HTTPS
Alternative: http Package
For simple REST calls that don't need interceptors, caching, or retry logic, use http instead of Dio.
Dio vs http
| Criteria | http | Dio |
|---|---|---|
| Interceptors | No | Yes, full chain |
| Retry logic | Manual | Built-in with backoff |
| Response caching | Manual | Plugin available |
| FormData / Multipart | Manual | Built-in |
| Cancel requests | No | Yes, CancelToken |
| Dependencies | Minimal (1 package) | Heavier |
| Use case | Simple CRUD APIs | Production API clients |
Use http for prototypes and simple fetch-and-display. Use Dio for production API clients that need auth, retry, and caching.
Basic http Patterns
import 'dart:convert';
import 'package:http/http.dart' as http;
// GET request
Future<Map<String, dynamic>> fetchData(http.Client client) async {
final response = await client.get(
Uri.parse('https://api.example.com/data'),
headers: {'Accept': 'application/json'},
);
if (response.statusCode == 200) {
return jsonDecode(response.body) as Map<String, dynamic>;
} else {
throw Exception('Failed to fetch: ${response.statusCode}');
}
}
// POST request
Future<void> createItem(http.Client client, Map<String, dynamic> body) async {
final response = await client.post(
Uri.parse('https://api.example.com/items'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode(body),
);
if (response.statusCode != 201) {
throw Exception('Failed to create: ${response.statusCode}');
}
}
Testing: Always accept http.Client as a parameter (not http.get() directly) to enable mock injection in tests.
Signals
- GitHub stars
- 30
- Forks
- 4
- Last commit
- Aug 2026
Advanced
- Item type
- skill
- Key
flutter-dio- Source
- github.com/dhruvanbhalara/skills
github.com/dhruvanbhalara/skills
Related picks
Skill · evanca
The pick for Dartwrite-dart
Skill · cfug
The pick for Dartflutter-auto-route-navigation
Skill · hoangnguyen0403
The pick for Fluttererror-tracking-flutter
Skill · posthog
The pick for Flutterteach
Skill · mattpocock
More in Dev toolsimplement
Skill · mattpocock
More in Dev tools