# Flutter Dio

> Implement HTTP networking with Dio including interceptors, retry logic, and response caching. Use when building API clients, configuring authentication headers, or handling network errors gracefully. Use when this capability is needed.

- Skill: `tomevault-io/flutter-dio` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/flutter-dio`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/flutter-dio/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/flutter-dio

---


# Networking with Dio

-   Use **Dio** as the primary HTTP client package.
-   Use type-safe model classes with `fromJson` / `toJson` factories 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 `DioException` into domain-specific `Failure` types.
-   Register interceptors centrally via `injectable` for 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 or `SharedPreferences`
-   All API communication MUST use HTTPS

---
> Source: [dhruvanbhalara/skills](https://github.com/dhruvanbhalara/skills) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->

