Dart Isolates: The Missing Guide for Production Flutter Apps
Concurrency primitives, ports, real-world patterns. The piece every Flutter dev wishes they had read before shipping their first heavy compute feature.
Read on
Read on Medium โKey takeaways
- Isolates are not threads. They share no memory, only messages.
- compute() is fine for one-shot heavy work. Long-lived isolates need spawn().
- SendPort / ReceivePort patterns power most production isolate use.
- Always close ports and exit isolates explicitly to avoid leaks.
Frequently asked questions
When should I use an isolate vs async/await?
Use async/await for I/O-bound work like network calls and file reads. Use an isolate when CPU-bound work would block the UI thread, typically anything over 16ms of synchronous compute on the main isolate.
What is the overhead of spawning an isolate?
Around 1-3ms on modern devices, plus the memory cost of a fresh heap. For one-shot work, compute() amortises this nicely. For repeated work, keep an isolate alive and message it.
Can isolates share memory?
Not in the general case. They communicate via copied messages. TransferableTypedData and Isolate.exit can move ownership of typed buffers without a copy, which is the main exception.
Why does my isolate code freeze the UI?
Most likely you are awaiting the isolate result on the main isolate without a yield. Wrap the call so the main isolate stays responsive while the worker runs.