Dart is a single threaded language, but it comes with a handy compute function
to spawn isolates. In a nutshell, the compute function is useful for doing
extra work on a different "thread"--it's actually an isolate--so your flutter
app does not experience "jank". Jank occurs when the UI doesn't render smoothly.
// A top level function
int computationallyExpensiveTask(int value) {
var sum = 0;
for (var i = 0; i <= value; i++) {
sum += i;
}
print('finished');
return sum;
}
// Call the function on another thread, keeping the UI thread free
final sum = await compute(computationallyExpensiveTask, 1000000000);