(错误)'Adhan' 类型的值不能从方法 'getAdhan' 中被 return 编辑,因为它有一个 return 类型的 'Future<List<Adhan>?>'

(ERROR) A value of type 'Adhan' can't be returned from the method 'getAdhan' because it has a return type of 'Future<List<Adhan>?>'

此代码用于从 json api 中获取数据,代码中只有一个错误,即错误:

error

 class RemoteService {
  Future<List<Adhan>?> getAdhan() async {
    var client = http.Client();

    var uri = Uri.parse("https://api.pray.zone/v2/times/today.json?city=paris");
    var response = await client.get(uri);
    if (response.statusCode == 200) {
      var json = response.body;
      return adhanFromJson(json);
    }
  }
}

我尝试在 Internet 和 YouTube 上搜索任何与我的问题类似的问题,但没有找到任何可以帮助我的东西。 我该如何解决这个错误?

你的函数名为 adhanFromJson 可能 return 是 Adhan,而 getAdhan 希望你 return 是 List<Adhan>null.

要么更改 getAdhan 的 return 类型,要么将 return 更改为 List<Adhan>