pigeon
30.0.4, released 3 days ago by flutter.dev
Type-safe code generator for communication between Flutter and host platforms.
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.
Works with
Packages commonly used together with pigeon: ones it builds on, ones built on it, and its own family.
- analyzerpigeon depends on itPerforms static analysis of Dart code for tool integration and embedding.
- yamlpigeon depends on itA Dart library for parsing YAML documents into Dart data structures.
- pub_semverpigeon depends on itVersions and version constraints implementing pub's versioning policy.
- dart_stylepigeon depends on itProvides an API and CLI to format Dart source code automatically.
- argspigeon depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- code_builderpigeon depends on itA fluent, builder-based library for generating valid Dart code programmatically.
- graphspigeon depends on itGraph algorithms that operate on graphs in any representation.
- superwallkit_flutterBuilt on pigeonFlutter plugin for remote paywall configuration and analytics