【发布时间】:2021-11-02 02:15:16
【问题描述】:
我有一个以 JSON 格式返回地点列表的 API,它在邮递员上运行良好,但我无法让它在 Flutter 上返回。
这里是返回所有地点的函数
Future<List<PlacesModel>> getAllPlaces() async {
final Storage _localStorage = window.localStorage;
List<PlacesModel> allPlaces = [];
Map<String, String> headers = {
'Content-type': 'application/json',
'Authorization': 'Bearer ${_localStorage['token']}'
};
final allPlacesURl = Uri.parse("http://localhost:3000/common/getPlaces/0");
var response = await http.get(allPlacesURl, headers: headers);
if(response.statusCode == 200)
{
final decodee = "[" + response.body +"]";
List body = json.decode(decodee);
allPlaces = body.map((e) => PlacesModel.fromJson(e)).toList();
return allPlaces;
}
}
但它只返回 Instance of '_Future<List<PlacesModel>>' 而不是实际的 json 列表。
【问题讨论】: