📱 Flutter
Intermediate
What is the compute() function in Flutter?
Answer
compute() is a helper function that runs a given function in a background isolate and returns the result to the main isolate as a Future. It takes a top-level or static function and a single argument: final result = await compute(parseJson, jsonString). This is the recommended way to offload heavy synchronous work (like parsing a large JSON response) off the main UI thread without the full complexity of manually managing isolates. The function and its argument must be serializable for isolate message passing.