首页 > 解决方案 > 如何返回未来在颤振?

问题描述

我正在 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'

有没有其他方法可以返回该变量?

谢谢

标签: flutterdart

解决方案


Future<http.Response> 

使用 http,因为这就是您导入它的方式。


推荐阅读