当我尝试解码JSON时,出现以下错误:
期望值的类型为'FutureOr<List>',但得到了'_JsonMap'类型
这是我从API获取数据的代码:
Future<List> getData() async {
final prefs = await SharedPreferences.getInstance();
final key = 'token';
final value = prefs.get(key) ?? 0;
String myUrl = "$serverUrl/userchecks";
http.Response response = await http.get(Uri.parse(myUrl), headers: {
'Accept': 'application/json',
'Authorization': 'Bearer $value'
});
print('Response status : ${response.statusCode}');
return json.decode(response.body);
}