flutter - 如何返回未来在颤振?
问题描述
我正在 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'
有没有其他方法可以返回该变量?
谢谢
解决方案
Future<http.Response>
使用 http,因为这就是您导入它的方式。
推荐阅读
- ruby-on-rails - 在 Digital Ocean 上存储 Rails 5.2+ 应用程序的 master.key 的位置
- operating-system - CPU总是在内核模式下执行指令吗?
- python - 正则表达式查找字符串字母,以及字符串数字组合的字符串字母python
- python - 熊猫读取带空格的文件名
- multithreading - 当我们在同一个测试计划下使用多个线程组时会发生什么?
- c# - .net 4.6.2 中的命名空间 system.web 错误中不存在类型或命名空间名称“HTTP”
- shell - 在 gnu makefile 中使用变量
- azure - 有没有办法为 yaml 模板(Azure Pipelines)中的对象数组设置默认值
- mongodb - 如何将地址与 Mongo 中的 'eq' 运算符进行比较
- python - 使用列表推导计算所有列表元素的总和