Answers for "dart compute example"

0

dart compute example

// 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);
Posted by: Guest on June-17-2021

Code answers related to "Dart"

Browse Popular Code Answers by Language