Authored by:
Pigeon is a code generator tool to make communication between Flutter and the host platform type-safe, easier, and faster. Pigeon generates automated code, which defines the channels to communicate from Flutter to native code and vice versa so that users do not have to write the channel definitions for iOS and Android, but instead, only write about the details needed above this communication bridge.
With the help of Pigeon, one can communicate to the host platform to perform operations, which is not supported over Flutter yet.
To add the Pigeon module to dev dependencies, follow the instructions here: https://pub.dev/packages/pigeon
1. Then, generate a dart file to define an abstract class containing a host API or Flutter API and define the configuration to generate dart and native files.
2. Run the Pigeon command to generate respective dart files and native code files, which will be used for Flutter to native communication, and vice versa.
e.g.: flutter pub run pigeon --input pigeon/facebook/facebook.dart --dart_out lib/core/platform/facebook/facebook.dart --objc_header_out ios/Runner/Source/Facebook/FacebookTargetMessage.h --objc_source_out ios/Runner/Source/Facebook/FacebookTargetMessage.m —java_out ./android/app/src/main/kotlin/au/com/test/flutter_test/facebook/FacebookTargetMessage.java --java_package "au.com.test.flutter_test.facebook"
3. To communicate through Pigeon, call the respective Flutter class from the generated dart file along with the method and pass the parameter to the methods as required, and it can be further accessed in the native code as per requirement.
4. The methods from the abstract class can be overridden to implement it as per the requirement, e.g. integration of the Facebook SDK was done on the native side rather than Flutter itself.
Example: /Flutter-Test/pigeon/facebook/facebook.dart
Have questions? Please leave a comment below and someone from the Community or Google Cloud team will be happy to help.