Skillshub 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)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/flutter-retrofit-networking" ~/.claude/skills/comeonoliver-skillshub-flutter-retrofit-networking && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/flutter-retrofit-networking/SKILL.mdsource content
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('/route'), @POST('/route/{id}/cancel') with @Path('id')). Methods must return
.Future<DTO> - DTOs (Data Transfer Objects): Use @freezed and @JsonSerializable for all response/request bodies.
- Mapping: Data sources MUST map DTOs to Domain Entities (e.g.,
).userDto.toDomain() - Safe Enums: Always use @JsonKey(unknownEnumValue: OrderStatus.unknown) for DTO enums with an
fallback value to prevent crashes when the backend introduces new values.unknown - AuthInterceptor: Logic for
injection inAuthorization: Bearer <token>
.onRequest - Token Refresh: Handle 401 Unauthorized in
by checkingonError
, locking Dio, callingDioException
, updating the stored token, and retrying viarefreshToken()
.dio.fetch(err.requestOptions) - Failures: Map
to customDioException
objects (ServerFailure, NetworkFailure).Failure
Anti-Patterns
- No Manual JSON Parsing: Do not use
; use Retrofit's generated mappers.jsonDecode(response.body) - No Global Dio: Do not use a static global Dio instance; use dependency injection.
- No Try-Catch in API: Do not put
inside the Retrofit interface methods.try-catch - 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