【发布时间】:2021-07-10 02:00:10
【问题描述】:
我正在尝试将列表 (List<int> danceId) 传递给我的 API 调用中的参数。它是一个 MultipartRequest API 调用请求。但是当我打电话给我一个错误时
type '_InternalLinkedHashMap<String, Object>' is not a subtype of type 'Map<String, String>'
这是我的 API 请求方法
Future<http.Response> patchApiCall(String url, String token, Map param,
String imageKey, File file) async {
var responseJson;
var uri = Uri.parse(url);
var request = http.MultipartRequest("PATCH", uri);
request.headers.addAll({"Authorization": token});
request.fields.addAll(param); /// Here are comes an error
if (file != null) {
var img = await http.MultipartFile.fromPath(imageKey, file.path);
request.files.add(img);
}
try {
final response =
await request.send().timeout(const Duration(seconds: 60));
var res = await http.Response.fromStream(response);
responseJson = res;
} on SocketException {
throw FetchDataException("You are not connected to internet");
} on TimeoutException catch (e) {
print('Time out');
throw TimeoutException('Time out');
}
return responseJson;
}
我将这个列表 List<int> danceId 作为参数中的数组传递
调用参数:
{first_name: Test First, last_name: Test, email: Test@test.com, date_of_birth: 2021-04-13, about: 123456789, dance_styles: [3, 2, 1]}
我也尝试"dance_styles": json.encode(danceStyleId)this,但没有运气。现在如何传递参数?
【问题讨论】:
-
能否请您在使用响应的地方添加代码?
-
我只显示列表的响应,但首先我无法进行 API 调用,这是我的问题。
标签: api flutter dart parameters httprequest