Skip to content
pubscout

chopper_generator

8.7.1, released 7 weeks ago by hadrienlejard.io

Generates type‑safe Chopper client code from annotated service interfaces.

$ flutter pub add chopper_generator
Source repository

What it does

It reads Dart files with @ChopperApi annotations and produces .chopper.dart files containing request methods, serializers, and error handling. The generated code works with the Chopper runtime to perform HTTP calls.

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

Use it when

  • You want compile‑time generated REST client code with minimal boilerplate
  • You already use the Chopper package for networking
  • You prefer strongly typed API interfaces over manual request building

Skip it when

  • You need a runtime‑only solution without build_runner
  • You prefer a different HTTP client API such as Dio or Retrofit

Strengths

  • Reduces boilerplate by generating request code
  • Integrates tightly with Chopper’s interceptor and serialization system
  • Supports advanced features like query parameters and abortable requests

Weaknesses

  • Requires build_runner and source_gen setup
  • Only works with Chopper; not a standalone HTTP client
  • Generated code can be harder to debug than hand‑written requests

Setup

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

Add dev:chopper_generator and dev:build_runner to dev_dependencies, then run `dart run build_runner build --delete-conflicting-outputs`.

import 'package:chopper/chopper.dart';

@ChopperApi()
abstract class MyService extends ChopperService {
  @Get(path: '/users')
  Future<Response> getUsers();
}

void main() async {
  final chopper = ChopperClient(services: [MyService.create()],);
  final service = chopper.getService<MyService>();
  final response = await service.getUsers();
  print(response.body);
}

Alternatives

Packages that do the same job and could replace chopper_generator.

  • retrofit

    Provides similar annotation‑based code generation for HTTP clients without needing Chopper

  • dio

    Offers a powerful, hand‑coded HTTP client with interceptors and FormData support

  • http

    Simple, low‑level HTTP client for cases where code generation is unnecessary

Works with

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