【发布时间】:2018-06-29 21:16:47
【问题描述】:
我有这个:
List<String> _filters = <String>[8, 11];
我将这个_filters 传递到这个端点:
this.api.setInterests(token, _filters)
.then((res) {
print(res);
});
看起来像这样:
Future setInterests(String token, List<String> interests) {
return _netUtil.post(BASE_URL + "/setinterests", body: {
"token": token,
"interests": interests
}).then((dynamic res) {
return res;
});
}
传递_filters 总是抛出错误:
type 'List<String>' is not a subtype of type 'String' in type cast
我不知道飞镖还想从我这里得到什么。
【问题讨论】:
-
检查token是否也是字符串类型。还尝试使用 var 而不是 List
定义 _filters并删除。对于 Dart 中的大多数用途,这应该足够了。 -
已检查。
token是一个字符串。它来自final token = prefs.getString('token');。更改为var并不能解决此问题。问题是,错误消息完全没有意义,所以调试甚至开始都含糊不清 -
使用 var 会抛出这个
type 'List<dynamic>' is not a subtype of type 'String' in type cast。 -
你确定
body可以接收List的吗?看起来它正试图将其转换为String给我,这显然不起作用。 -
@creativecreatorormaybenot 如果是这样,我该如何解决?