首页 > 解决方案 > 输入'列表' 不是类型转换中类型 'String' 的子类型

问题描述

我有这个:

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

我不知道飞镖还想从我这里得到什么。

标签: dartflutter

解决方案


我找到了答案。我刚刚添加.toString()_filters列表中。

  this.api.setInterests(token, _filters.toString())
  .then((res) {
    print(res);
  });

推荐阅读