Android Studio 中无法识别 Dart 关键字“await”

Tel*_*ues 4 dart android-studio flutter

考虑以下 Dart 源代码(Flutter 项目):

void foo() {
  await bar();
}

Future<void> bar() async {
  print("test");
}
Run Code Online (Sandbox Code Playgroud)

这导致在Android Studio中的以下错误: The built-in identifier 'await' can't be used as a type

如果我将其更改为(await bar());然后我收到错误Unexpected text 'await'

我在这里缺少什么?

内置标识符 'await' 不能用作类型 意外文本“等待”

che*_*ins 7

foo()方法需要用 标记async

Future<void> foo() async {
  await bar();
}
Run Code Online (Sandbox Code Playgroud)