Flutter · One codebase, native feel

How do platform channels work and what are the failure modes?

Hardplatform channelsmethodchannelpigeonnativeUpdated Oct 2026
Quiz this track

Short answer

Platform channels send typed messages between Dart and native code asynchronously. MethodChannel handles calls, EventChannel streams native events, and Pigeon generates type-safe bindings.

A channel has a name and a codec. Dart invokes a method with arguments, the engine serialises the message, and the native handler replies on the platform thread. The call is asynchronous from Dart, but the native handler must not block the main thread for long or it will cause dropped frames and watchdog issues.

dart
static const channel = MethodChannel('app.example/battery');

Future<int> batteryLevel() async {
  final level = await channel.invokeMethod<int>('getBatteryLevel');
  return level ?? -1;
}
kotlin
class MainActivity : FlutterActivity() {
  private val channelName = "app.example/battery"

  override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
    super.configureFlutterEngine(flutterEngine)
    MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channelName)
      .setMethodCallHandler { call, result ->
        if (call.method == "getBatteryLevel") {
          result.success(87)
        } else {
          result.notImplemented()
        }
      }
  }
}
  • MethodChannel is request-response; EventChannel is a native-to-Dart event stream
  • StandardMethodCodec supports primitives, lists, maps and typed data, not arbitrary objects
  • Return PlatformException with a code, message and details for failures
  • Channel names must be unique and stable across releases
  • Pigeon generates typed Dart, Kotlin, Swift and Objective-C bindings to reduce stringly-typed errors

Failure modes in production

A missing handler throws MissingPluginException, often because the plugin was not registered or the app was not rebuilt after adding native code. Version skew between Dart and native code produces mismatched arguments. Blocking the platform thread delays the reply and can freeze the UI. Background isolates cannot use channels without configuring the background messenger.

Prefer a maintained plugin over a custom channel. Write a channel when you own the native code and the capability is genuinely app-specific.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1When would you use EventChannel instead of MethodChannel?
  2. 2What causes MissingPluginException?
  3. 3Why is Pigeon safer than hand-written channel strings?
  4. 4How do you call a channel from a background isolate?

Say it in the interview

Platform channels pass serialised messages between Dart and native code. MethodChannel is request-response, EventChannel streams events, and Pigeon generates typed bindings so method names and arguments are checked. The calls are async in Dart, but native handlers still run on a platform thread, so I keep them short. In production the usual failures are missing registration, version skew and background isolates without channel setup.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Flutter mock interview and get scored feedback on depth, clarity and confidence.