Skip to content
pubscout

pigeon

30.0.4, released 3 days ago by flutter.dev

Type-safe code generator for communication between Flutter and host platforms.

$ flutter pub add pigeon
Source repository

What it does

Generates structured, type-safe Dart and native host platform code (Kotlin, Java, Swift, Objective-C, C++, GObject) from an interface definition file. It replaces manual platform channel serialization and string-based method routing with generated message codecs and typed method interfaces. It also provides a direct native interop mode using FFI and JNI for high-performance and synchronous host calls.

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

Use it when

  • Building Flutter plugins or apps with extensive custom native platform integrations.
  • Eliminating manual string-based MethodChannel messaging and binary buffer encoding errors.
  • Needing type-safe bidirectional communication (Host APIs and Flutter APIs) across iOS, Android, macOS, Windows, or Linux.

Skip it when

  • Exposing generated classes directly in your package's public API, as generated code changes frequently between versions.
  • Your project only needs trivial, one-off platform channel calls where code generation adds unnecessary complexity.

Strengths

  • Supports multiple host targets: Android (Kotlin/Java), iOS/macOS (Swift/Obj-C), Windows (C++), and Linux (GObject).
  • Offers both standard platform channels and high-performance native interop (direct Dart FFI and JNI).
  • Generates typed data models, error handling, asynchronous wrappers, and event channels.

Weaknesses

  • Frequent breaking changes in generated code across package updates make it unsuitable for public API exposure.
  • Native interop mode is complex to set up and has preview limitations regarding multi-engine routing.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
No
Direct dependencies
10

Requires defining an API schema Dart file outside lib/, running the Pigeon CLI generator, and integrating generated native source files into platform-specific build configurations (Xcode, CMake, Gradle).

import 'package:pigeon/pigeon.dart';

class SearchRequest {
  String? query;
}

class SearchReply {
  String? result;
}

@HostApi()
abstract class Api {
  SearchReply search(SearchRequest request);
}

Alternatives

Packages that do the same job and could replace pigeon.

  • ffi

    Use when calling C or C-compatible native libraries directly without needing platform channel code generation for mobile frameworks.

Works with

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