【问题标题】:How to return Future<Response> in Flutter?如何在 Flutter 中返回 Future<Response>?
【发布时间】:2021-10-07 06:57:00
【问题描述】:

我正在 Flutter 上编写一个从 API 获取数据的函数。函数完成后,我需要返回变量为Future&lt;Response&gt;

函数如下:

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'

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

谢谢

【问题讨论】:

标签: flutter dart


【解决方案1】:
Future<http.Response> 

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

【讨论】:

    猜你喜欢
    • 2021-10-05
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-22
    • 2022-01-19
    • 2020-08-01
    相关资源
    最近更新 更多