Platform channels and native integration
To reach a platform capability Flutter does not provide, you use a platform channel: the Dart side sends a message and the native side (Kotlin/Swift) replies.
There are three kinds:
- `MethodChannel` — a one-off call and response (by far the most used)
- `EventChannel` — a continuous stream from the native side (sensors, battery state)
- `BasicMessageChannel` — free-form two-way messaging
Messages are passed asynchronously and serialised automatically — only simple types cross (numbers, strings, lists, maps); you cannot pass an object directly.
Interview tip. The strong answer to "when do you drop to native code?" starts with checking pub.dev first: for most needs — camera, location, notifications, file picking — a well-maintained plugin exists and writing your own channel is wasted effort. I write native code only when: (1) an in-house SDK has to be integrated, (2) no plugin exists or the one that does is abandoned, (3) performance requires a platform-specific API. That ordering shows practical judgement.
📚 Sources and documentation
- Platform channelsofficialdocs.flutter.dev
Channel kinds, the type-conversion table and Kotlin/Swift examples are all in the official guide.
- MethodChannel classofficialapi.flutter.dev
- Testing pluginsofficialdocs.flutter.dev