Skip to content
pubscout

retrofit

4.10.0, released 3 months ago by hitrevor.com

Dart Dio client generator using source_gen

WASM-readyRock solid
$ flutter pub add retrofit
Source repository

What it does

Retrofit.dart generates typed Dio API clients from annotated interfaces. It uses source_gen to produce boilerplate, enabling compile‑time type safety and easy HTTP method mapping.

AI-written summary of version 4.10.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Need a typed API client for a REST service
  • Want to avoid writing repetitive Dio request code
  • Prefer a Retrofit‑style declarative API definition
  • Require support for many HTTP methods and custom headers

Skip it when

  • You prefer not to use code generation
  • You are already using the plain http package
  • You need a lightweight solution without Dio

Strengths

  • Automatic code generation reduces boilerplate
  • Strong type safety with Dart generics
  • Supports custom headers, query params, body extras
  • Extensible via CallAdapters and DartMappable parser

Weaknesses

  • Requires build_runner and extra dev dependency
  • Adds compile‑time overhead
  • Tied to Dio, not the standard http client

Setup

Kind
Pure Dart
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
2

Add retrofit and retrofit_generator to dependencies/dev_dependencies, run `dart pub run build_runner build` or watch. No special permissions needed.

import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';

@RestApi(baseUrl: 'https://api.example.com/')
abstract class ApiService {
  factory ApiService(Dio dio, {String? baseUrl}) = _ApiService;

  @GET('/users')
  Future<List<User>> getUsers();
}

@JsonSerializable()
class User {
  const User({this.id, this.name});
  factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
  final int? id;
  final String? name;
  Map<String, dynamic> toJson() => _$UserToJson(this);
}

Alternatives

Packages that do the same job and could replace retrofit.

  • http

    Standard HTTP client with no codegen, lighter weight

Works with

Packages commonly used together with retrofit: ones it builds on, ones built on it, and its own family.