Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart keyword 'await' not recognized in Android Studio

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'

like image 820
Telmo Marques Avatar asked Dec 25 '18 22:12

Telmo Marques


Video Answer


1 Answers

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

Future<void> foo() async {
  await bar();
}
like image 51
chemamolins Avatar answered Oct 23 '22 15:10

chemamolins