Skip to content
pubscout

retrofit_generator

10.3.3, released 3 weeks ago by hitrevor.com

Generates Dio client code from Retrofit‑style annotations.

Rock solid
$ flutter pub add retrofit_generator
Source repository

What it does

It reads abstract classes annotated with @RestApi and produces concrete implementations that use Dio for HTTP calls. Supports built_collection, lean_builder and custom builder options.

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

Use it when

  • You want type‑safe, compile‑time generated REST clients in Dart/Flutter
  • You prefer Retrofit‑style declarative API definitions over manual Dio requests

Skip it when

  • You need runtime‑only solutions without build_runner
  • You require advanced features not covered by Retrofit annotations

Strengths

  • Reduces boilerplate for Dio calls
  • Integrates with build_runner and supports custom options
  • Keeps API definitions clean and type‑safe

Weaknesses

  • Requires code generation step (build_runner)
  • Limited to features exposed by the package’s annotations

Setup

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

Add retrofit_generator and retrofit to pubspec, run flutter pub get, then execute flutter pub run build_runner build to generate code.

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

part 'example.g.dart';

@RestApi(baseUrl: "https://api.example.com")
abstract class ApiClient {
  factory ApiClient(Dio dio, {String baseUrl}) = _ApiClient;

  @GET("/users/{id}")
  Future<User> getUser(@Path("id") String id);
}

void main() async {
  final dio = Dio();
  final client = ApiClient(dio);
  final user = await client.getUser('123');
  print(user);
}

Alternatives

Packages that do the same job and could replace retrofit_generator.

Works with

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