Flutter onRefresh回调返回null

Flutter onRefresh回调返回null,flutter,dart,Flutter,Dart,我正在使用RefreshIndicator从internet刷新数据,但当我从顶部向下拉时,刷新图标没有消失,同时发生了一个错误: ════════ Exception caught by material library ══════════════════════════════════ The following assertion was thrown when calling onRefresh: The onRefresh callback returned null. The R

我正在使用
RefreshIndicator
从internet刷新数据,但当我从顶部向下拉时,刷新图标没有消失,同时发生了一个错误:

════════ Exception caught by material library ══════════════════════════════════
The following assertion was thrown when calling onRefresh:
The onRefresh callback returned null.

The RefreshIndicator onRefresh callback must return a Future.
════════════════════════════════════════════════════════════════════════════════
下面是我的代码,其中声明了获取数据的方法:


Future<void> getApiData() async {
  return fetchWorldData();
}

Future<Map<String, dynamic>> fetchWorldData() async {
  Response response = await get(Uri.parse(
      'https://disease.sh/v3/covid-19/countries/${CurrentCountry.currentcountry}'));
  return json.decode(response.body);
}

如果您能帮助我,我将非常感激。

它将返回null,因为您没有在此处放置
wait
,因此它会立即返回结果(而不是等待API获取实际数据) 那么就这样做吧

onRefresh: () async {
  await getApiData();
}

您的回调函数正在调用您的函数,但实际上并没有返回其结果

你可以做:

onRefresh: () {
  return getApiData();
}
甚至更短:

onRefresh: () => getApiData()
或者因为你的签名完全匹配


错误消失了,但UI中显示的数据仍然没有更改。
onRefresh: () => getApiData()
onRefresh: getApiData