Talking to Native: FFI, Pigeon, and Knowing Which One You Need
A MethodChannel typo cost us three days and a hotfix release, and the compiler never said a word. That's the whole story of Flutter native interop in one sentence: the easy path is a stringly-typed message bus that fails silently in the field, and almost everyone reaches for it first. Every Flutter developer's first brush with native code goes the same way. You need something the framework…
Flutter provides three ways to interoperate with native code: dart:ffi, Pigeon, and raw MethodChannel. These methods are not interchangeable, and picking the wrong one leads to pain in the long run.
dart:ffi is the fastest path and allows calling C, Rust, or any other language with a C ABI directly, synchronously, and with zero serialization. Pigeon is a code generator that creates type-safe method channels for you, using the same transport as raw channels but with compiler checks on both sides. Raw MethodChannel/EventChannel is a manually-built message bus between Dart and the platform, which is asynchronous, dynamically typed, and requires manual handling on both ends.
FFI is meant for calling existing native functions, Pigeon is for working with platform APIs and getting a typed contract, while raw channels are for event streams and plugins that Pigeon can't handle yet. The key decision is between FFI and Pigeon, with raw channels being a fallback for specific cases.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.