Async Programming Flutter Interview Questions
6 questions
What's the difference between a broadcast StreamController and a single-subscription one?
A single-subscription StreamController allows only one listener ever, and buffers events until that listener subscribes; a broadcast StreamController allows multiple simultaneous listeners but doesn't buffer events for listeners that subscribe late.
What are the common pitfalls of using FutureBuilder?
The most common FutureBuilder bug is passing a new Future instance on every build (e.g. calling a function directly in the future: parameter), which re-triggers the loading state on every rebuild instead of just once.
What is a Completer in Dart and when would you use one?
A Completer lets you manually create and control a Future, resolving it later with .complete() or .completeError() — useful for wrapping callback-based APIs into a Future-based one.
What are Zones in Dart used for?
A Zone is an execution context that lets you intercept and customize behaviors like error handling, print output, and timers for all code running within it — most commonly used to catch otherwise-uncaught async errors app-wide.
What's the difference between Timer and Future.delayed?
Future.delayed runs a callback once after a delay and resolves; Timer can either fire once (Timer()) or repeatedly (Timer.periodic()), and importantly gives you a handle you can explicitly cancel.
What are async* generator functions in Dart?
An async* function is a generator that returns a Stream instead of a Future, letting you yield multiple values over time using the same imperative, sequential-looking code style as a normal async function.