When to choose EventChannel over MethodChannel and native setup
It tests streaming versus one-shot platform communication. Pick EventChannel for ongoing native events like sensor data; register a StreamHandler on Android or iOS that feeds an event sink, then consume in Dart via receiveBroadcastStream.
What's really being asked
This question tests whether you can distinguish between discrete request-response interactions and persistent unidirectional data flows across the Flutter platform channel boundary. Interviewers want to see that you know MethodChannel is designed for one-off async invocations while EventChannel is purpose-built for streams of data that originate on the native side and are consumed reactively in Dart.
The full answer
A good answer hits four things in order. First, the decision criteria: choose EventChannel when the native layer produces a continuous sequence of events such as sensor readings, GPS coordinates, or Bluetooth status updates where the Dart side is a passive consumer. Second, native setup: on Android you create an EventChannel in the MainActivity or plugin and set a StreamHandler that receives an EventSink; on iOS you use FlutterEventChannel and implement FlutterStreamHandler to obtain a FlutterEventSink. Third, emission mechanics: the native side pushes data by calling success on the sink whenever new data arrives, and it must handle the sink being null before the first listener attaches. Fourth, Dart consumption: you instantiate an EventChannel with the exact same name, call receiveBroadcastStream to get a Stream, and listen to it with normal Stream APIs while handling onCancel to clean up native resources when the last listener detaches.
The mistakes people make
The biggest red flag is suggesting a Timer that repeatedly calls MethodChannel to simulate streaming. This shows a misunderstanding of backpressure and battery efficiency. Another mistake is forgetting stream lifecycle management, such as not removing the native listener when the Dart subscription cancels, which causes memory leaks and events firing into a void. Some candidates also confuse two-way communication with EventChannel; it is not a duplex channel for sending commands from Dart to native, it is strictly native-to-Dart streaming.
What usually comes next
Interviewers often ask how you would handle backpressure if native emits faster than Dart consumes. They may also ask how to pass arguments when setting up the stream, which is done by providing a codec-compatible argument to receiveBroadcastStream. Another common follow-up is error propagation: explain how you call error on the native event sink and map it to Dart stream errors.
A concrete example
A practical example is reading the device accelerometer at sixty hertz. On the Android side you register a SensorEventListener, create an EventChannel named com.example.sensors.accel, and in your StreamHandler onListen callback you attach to the hardware sensor and forward SensorEvent values to the EventSink. On the Dart side you create an EventChannel with the identical name, invoke receiveBroadcastStream, and map the incoming list of doubles to an AccelerometerData object. When the widget disposes you cancel the stream subscription, which triggers onCancel on the native side so you unregister the SensorEventListener and stop the hardware to save power.
Interview question
You need to stream device accelerometer data from native code to Dart at 60 Hz. Which approach is correct?
- a.Use an EventChannel to send commands from Dart to native and receive discrete responses for each sensor sample.
- b.Register the native sensor listener once in MainActivity and never unregister it, relying on Dart to ignore events when the stream is no longer needed.
- c.Use a MethodChannel and invoke it from a Dart Timer every 16 ms to poll the native layer for the latest reading.
- d.Use an EventChannel with a native StreamHandler that pushes data to an EventSink, and consume it in Dart via receiveBroadcastStream.Correct
Why? this is the answer
EventChannel is designed for continuous native-to-Dart streaming through a native StreamHandler that feeds an EventSink, consumed in Dart with receiveBroadcastStream. Option C represents a common anti-pattern that wastes battery and lacks backpressure handling because MethodChannel is intended for one-off async invocations, not persistent data flows.
Just read this? Test yourself on what you have been reading.
Read the original → docs.flutter.dev
- #flutter
- #platform-channels
- #eventchannel
- #methodchannel
- #native-integration
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on flutter — each one lists the topics its interview covers.
See open roles