我正在 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'
还有其他方法可以返回该变量吗?
谢谢
答案 0 :(得分:1)
Future<http.Response>
使用 http,因为这是您导入它的方式。