Isolate là các luồng thực thi riêng biệt không chia sẻ bộ nhớ — mỗi isolate có heap và event loop riêng.
- Dùng isolate cho công việc tốn CPU (parse JSON lớn, mã hóa, xử lý ảnh) để tránh block main UI thread.
- API hiện đại (2025):
Isolate.run()(Dart 2.19+ / Flutter 3.7+) cho tác vụ one-shot ngắn gọn;compute()là Flutter helper wrapper.Isolate.spawn()vẫn dùng cho long-lived isolate cần giao tiếp liên tục qua SendPort/ReceivePort. - Isolate nhẹ hơn OS thread nhưng nặng hơn async/await, nên dùng tiết kiệm.
Isolates are separate execution threads that don't share memory — each has its own heap and event loop.
- Use isolates for CPU-intensive work (JSON parsing, encryption, image processing) to avoid blocking the main UI thread.
- Modern API (2025): use
Isolate.run()(Dart 2.19+ / Flutter 3.7+) for concise one-shot background tasks, orcompute()as the Flutter helper wrapper. - Use
Isolate.spawn()for long-lived isolates that need continuous communication via SendPort/ReceivePort. - They are lighter than OS threads but heavier than async/await.