What is the compute() function in Flutter?
Why Interviewers Ask This
This tests whether you can apply Flutter knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
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.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Flutter codebase.