【发布时间】:2023-04-03 17:20:01
【问题描述】:
我需要发出一个 HTTP GET 请求来检索一些过滤后的数据。 我的 API 接受 3 个参数数组,在我的代码中我有 3 个不同的参数列表。 是否可以从 3 个 int 列表中创建包含具有相同键和不同值的参数的 Map?
Future<List<Tour>> fetchFilteredTours(List<int> bikeTypeIds,
final List<int> difficultyIds, final List<int> locationIds) async {
final Map<String, String> qryParams = {
};
//How to create my qryParams with all arrays values?
//Something like
qryParams.add(Map.fromIterable(bikeTypeIds, key: (e) => 'bikeTypeId', value: (e) => e));
final response = await http
.get(Uri.http('myDomain', '/api/search/tours', qryParams));
return parseResponse(response);
}
想要的结果是{{protocol}}://{{url}}/api/search/tours?bikeTypeId=1&bikeTypeId=2&difficultyId=1&locationId=1
【问题讨论】:
-
使用
String,而不是Map。 -
是的,我可以使用字符串。但我的是一个
map研究案例 -
你希望 qryParams ['bikeTypeId'] 返回什么?
-
问题不是我想返回什么,而是
Uri.http()接受什么。它接受Map<String,String>,但在地图中您不能放置具有相同键的条目