Skip to content
pubscout

ffigen

23.0.0, released 6 weeks ago by tools.dart.dev

Generator for FFI bindings, using LibClang to parse C, Objective-C, and Swift files.

$ flutter pub add ffigen
Source repository

What it does

FFIgen parses C, Objective-C, and Swift header files using LibClang to generate Dart FFI binding boilerplate. It automates calling native code from Dart via a programmatic generator API.

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

Use it when

  • You need to call C or Objective-C native libraries from Dart.
  • You want to avoid manually writing Dart FFI bindings for large native headers.

Skip it when

  • You are writing a pure Dart app with no native interop requirements.
  • You only need simple bindings that are faster to write by hand.

Strengths

  • Automates generating complex Dart FFI bindings from native headers.
  • Supports C, Objective-C, and experimental C++ features.

Weaknesses

  • Requires LLVM and LibClang installed on the host system to run.
  • YAML configuration format is deprecated in favor of the programmatic Dart API.

Setup

Kind
FFI (native library)
Effort
High
Code generation
No
Direct dependencies
18

Requires LLVM / libclang installed on your operating system (e.g., libclang-dev on Linux, LLVM on Windows via winget/installer, or Xcode command line tools on macOS).

import 'package:ffigen/ffigen.dart';
import 'dart:io';

Future<void> main() async {
  final packageRoot = Platform.script.resolve('../');
  final generator = FfiGenerator(
    output: Output(dart: DartOutput(path: packageRoot.resolve('lib/add.g.dart'))),
    input: Input(entryPoints: [packageRoot.resolve('src/add.h')]),
  );
  await generator.generate();
}

Alternatives

Packages that do the same job and could replace ffigen.

Works with

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