为什么我不能通过等待将变量分配给异步调用的结果?

why cant i assign a variable to the result of an async call via await?

我有以下几行,但不起作用。它说:预期;在 await.

之后
import "package:http/http.dart" as http;
http.Response rslt = await http.post(/*...*/);

由于 http.post 根据定义 returns a Future(Response)await 不能解决这个问题吗?我以为会。

https://www.dartdocs.org/documentation/http/0.11.3%2B3/http/http-library.html

从某种意义上说,我一直认为 await 会打开 Future 对象并将其分配给任何...在本例中为 Response 变量。

我很确定包含此代码的 method/function 缺少 async 修饰符。

Future someFunc() async {
  import "package:http/http.dart" as http;
  http.Response rslt = await http.post(/*...*/);
}

如果函数体没有 async 修饰符,async 是一个有效的标识符,因为 async 不是关键字。