Pigeon is a code generator tool to make communication between Flutter and the host platform type-safe, easier, and faster.
Pigeon removes the necessity to manage strings across multiple platforms and languages. It also improves efficiency over common method channel patterns. Most importantly though, it removes the need to write custom platform channel code, since pigeon generates it for you.
For usage examples, see the Example README.
Currently pigeon supports generating:
Pigeon uses the
StandardMessageCodec so it supports any datatype platform channels support.
Custom classes, nested datatypes, and enums are also supported.
Nullable enums in Objective-C generated code will be wrapped in a class to allow for nullability.
While all calls across platform channel APIs (such as pigeon methods) are asynchronous, pigeon methods can be written on the native side as synchronous methods, to make it simpler to always reply exactly once.
If asynchronous methods are needed, the
@async annotation can be used. This will require results or errors to be returned via a provided callback. Example.
All Host API exceptions are translated into Flutter
To pass custom details into
PlatformException for error handling, use
FlutterError in your Host API. Example.
FlutterError in Swift you must first extend a standard error. Example.
Host API errors can be sent using the provided
FlutterError class (translated into
For synchronous methods:
errorargument to a
For async methods:
FlutterErrorthrough the provided callback.
When targeting a Flutter version that supports the TaskQueue API the threading model for handling HostApi methods can be selected with the
flutter pub getthen
flutter pub run pigeonwith suitable arguments. Example.
abstract classwith either
@HostApi()being for procedures that are defined on the host platform and the
@FlutterApi()for procedures that are defined in Dart.
./android/app/src/main/javadirectory for compilation.
./windowsdirectory for compilation, and to your
Pigeon also supports calling in the opposite direction. The steps are similar but reversed. For more information look at the annotation
@FlutterApi() which denotes APIs that live in Flutter but are invoked from the host platform. Example.
File an issue in flutter/flutter with “[pigeon]” at the start of the title.