运行Flutter项目时内部链接的哈希图错误

时间:2019-06-14 12:06:44

标签: flutter

我的代码中出现此错误。

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'FutureOr<List<dynamic>>'

这是我的代码:

Future<List> getmatches() async{
 String url="https://cricapi.com/api/cricketScore?apikey=oJmzPtpZJXcIQmxAjOlP5Zss1At1&unique_id=1034809";
  http.Response response=await http.get(url);
  return jsonDecode(response.body);

这是错误:

 Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a 
 subtype of type 'FutureOr<List<dynamic>>'

1 个答案:

答案 0 :(得分:0)

将函数的返回类型替换为Future<Map<String, dynamic>>,使它看起来像

Future<Map<String, dynamic>> getmatches() async {
 String url="https://cricapi.com/api/cricketScore?apikey=oJmzPtpZJXcIQmxAjOlP5Zss1At1&unique_id=1034809";
  http.Response response=await http.get(url);
  return jsonDecode(response.body);
}