> flutter-retrofit-networking
HTTP networking standards using Dio and Retrofit with Auth interceptors. Use when integrating Dio, Retrofit, or API auth interceptors in Flutter. (triggers: **/data_sources/**, **/api/**, Retrofit, Dio, RestClient, GET, POST, Interceptor, refreshing)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/flutter-retrofit-networking?format=md"Retrofit & Dio Networking
Priority: P0 (CRITICAL)
Type-safe REST API communication using Dio and Retrofit.
Structure
infrastructure/
├── data_sources/
│ ├── remote/ # Retrofit abstract classes
│ └── local/ # Cache/Storage
└── network/
├── dio_client.dart # Custom Dio setup
└── interceptors/ # Auth, Logging, Cache
Implementation Guidelines
- Retrofit Clients: Define abstract classes with
@RestApi(). Use standard HTTP annotations (@GET,@POST). - DTOs (Data Transfer Objects): Use
@freezedandjson_serializablefor all response/request bodies. - Mapping: Data sources MUST map DTOs to Domain Entities (e.g.,
userDto.toDomain()). - Safe Enums: Always use
@JsonKey(unknownEnumValue: ...)for DTO enums to prevent crashes when the backend introduces new values. - AuthInterceptor: Logic for
Authorization: Bearer <token>injection inonRequest. - Token Refresh: Handle
401 UnauthorizedinonErrorby locking Dio, refreshing, and retrying. - Failures: Map
DioExceptionto customFailureobjects (ServerFailure, NetworkFailure).
Anti-Patterns
- No Manual JSON Parsing: Do not use
jsonDecode(response.body); use Retrofit's generated mappers. - No Global Dio: Do not use a static global Dio instance; use dependency injection.
- No Try-Catch in API: Do not put
try-catchinside the Retrofit interface methods. - No Unsafe Enums: Do not leave enums in DTOs without handling unknown values from the server.
Reference & Examples
For RestClient definitions and Auth Interceptor implementation: See references/REFERENCE.md.
Related Topics
feature-based-clean-architecture | error-handling
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)