Pigeon is a code generation tool that adds type safety to Flutter’s Platform Channels. This document serves as an overview of how it functions to help people who would like to contribute to the project.
Pigeon generates a temporary file in its LaunchIsolate, the isolate that is spawned to run main()
, then launches another isolate, PigeonIsolate, that uses dart:mirrors
to parse the generated file, creating an AST, then running code generators with that AST.
Pigeon has 3 types of tests, you'll find them all in test.dart.
For local testing, always use test.dart
rather than run_tests.dart
, as run_tests.dart
is specifically a CI entrypoint. When iterating on a specific generator, you will likely want to use the -t
flag to specific only the relevant tests. Pass -l
to get a list of available tests for the -t
flag.
This is what the temporary generated code that the PigeonIsolate executes looks like (see State Diagram):
import 'path/to/supplied/pigeon/file.dart' import 'dart:io'; import 'dart:isolate'; import 'package:pigeon/pigeon_lib.dart'; void main(List<String> args, SendPort sendPort) async { sendPort.send(await Pigeon.run(args)); }
This is how dart:mirrors
gets access to the supplied Pigeon file.