flutter-networking-retrofit-dio
maintained by HoangNguyen0403
star
143
account_tree
48
verified_user
MIT License
name: Flutter Networking (Retrofit & Dio) description: HTTP networking standards using Dio and Retrofit with Auth interceptors. metadata: labels: [networking, retrofit, dio] triggers: files: ['/data_sources/', '/api/'] keywords: [Retrofit, Dio, RestClient, GET, POST, Interceptor, refreshing]
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()). -
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.
Reference & Examples
For RestClient definitions and Auth Interceptor implementation: See references/REFERENCE.md.
Related Topics
feature-based-clean-architecture | error-handling
chat Comments (0)
Sign in to join the discussion and leave a comment.
Skill Details
GitHub Stars
143
GitHub Forks
48
Created
Jan 2026
Last Updated
8 months ago
tools
tools security
Related Skills
Build your own?
Join 12,000+ developers contributing to the Claude ecosystem.
No comments yet. Be the first to share your thoughts!