Async function of the Dart programming language is not working properly Async function of the Dart programming language is not working properly dart dart

Async function of the Dart programming language is not working properly


Since Dart 2 sync code at the beginning of async functions is executed sync.
This was different in Dart 1.

A workaround would be

Future<bool> longWait(String prefix) async {  await Future.microtask((){});  for (int i = 0; i < 5; i++) {    print('$prefix $i');  }  return true;}

The code after the await is executed async and results in the desired behavior. (tested in DartPad)