Dart Analyze

Dart Analyze

Community Analyzer

Don't invoke asynchronous functions in non-async blocks DRT-W1017

Bug risk
Major

Making asynchronous calls in non-async functions is usually the sign of a programming error. In general these functions should be marked async and such futures should likely be awaited (as enforced by unawaited_futures).

DON'T invoke asynchronous functions in non-async blocks.

BAD:

void recreateDir(String path) {
  deleteDir(path);
  createDir(path);
}

Future<void> deleteDir(String path) async {}

Future<void> createDir(String path) async {}

GOOD:

Future<void> recreateDir(String path) async {
  await deleteDir(path);
  await createDir(path);
}

Future<void> deleteDir(String path) async {}

Future<void> createDir(String path) async {}