Dart keyword 'await' not recognized in Android Studio

Viewed 1818

Consider the following Dart source code (Flutter project):

void foo() {
  await bar();
}

Future<void> bar() async {
  print("test");
}

This is causing the following error on Android Studio: The built-in identifier 'await' can't be used as a type.

If I change it to (await bar()); then I get the error Unexpected text 'await'.

What am I missing here?

The built-in identifier 'await' can't be used as a type Unexpected text 'await'

1 Answers

The foo() method needs to be marked with async.

Future<void> foo() async {
  await bar();
}
Related