【发布时间】:2021-10-07 06:57:00
【问题描述】:
我正在 Flutter 上编写一个从 API 获取数据的函数。函数完成后,我需要返回变量为Future<Response>
函数如下:
final String apiUrl = "http://api.aladhan.com/v1/calendarByCity?city=Kayseri&country=Turkey&method=13&month=07&year=2021";
Future<Response> fetchData() async {
var result = await http.get(Uri.parse(apiUrl));
return result;
}
但是,我从编译器收到了这条消息:
The name 'Response' isn't a type so it can't be used as a type argument.
Try correcting the name to an existing type, or defining a type named 'Response'
还有其他方法可以返回该变量吗?
谢谢
【问题讨论】:
-
如果您从 API 获取数据,请参考我的答案stackoverflow.com/a/68533647/13997210 或stackoverflow.com/a/68594656/13997210
-
每当我坚持使用变量类型时。我做
print(v.runtimeType);这样我就可以确定我的返回类型。检查@Huthaifa Muayyad 的答案。 -
您还没有将
Response导入到您的代码中。检查http.get方法返回。