How can you properly implement Pigeon, Flutter's own official type safe code generation tool, to eliminate genuinely error prone manual string based method names and reduce the genuine risk of a mismatch between your Dart and native platform channel code?
Short answer
Pigeon lets you properly define your entire platform channel's own genuinely complete API using a genuinely simple Dart interface as a single shared source of truth, then automatically generates fully strongly typed corresponding Dart and native platform code for you, completely…
Advertisement
AModel answer
Pigeon lets you properly define your entire platform channel's own genuinely complete API using a genuinely simple Dart interface as a single shared source of truth, then automatically generates fully strongly typed corresponding Dart and native platform code for you, completely eliminating the genuine risk of a subtle mismatch between a specific method name or its own expected argument type on either side, a genuinely common and quite easy mistake to accidentally make when manually writing raw platform channel code entirely completely by hand, and this particular code generation approach considerably improves overall genuine reliability and maintainability specifically for a genuinely complex plugin with several separate different platform channel methods.
@HostApi()
abstract class BatteryApi {
int getBatteryLevel();
}
// Pigeon generates fully strongly typed Dart and native code from this single shared definitionReal-world example
A team building a genuinely complex custom plugin with over a dozen separate platform channel methods adopts Pigeon specifically to eliminate several genuinely subtle bugs previously caused by an accidental mismatch between a specific manually typed method name on the Dart side and its own corresponding native implementation.
Likely follow-ups
- How does Pigeon genuinely actually work internally to generate this particular required code?
- What genuinely other specific benefits does Pigeon provide beyond simply just improving type safety alone?
Related topics