dart - 类型 'List<String>' 不是类型转换中类型 'String' 的子类型

标签 dart flutter

我有这个:

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

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

最佳答案

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

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

关于dart - 类型 'List<String>' 不是类型转换中类型 'String' 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51109516/

相关文章:

flutter - 限制TextField中允许的字符数

android - 如何部署Dart Web应用程序以执行系统Shell脚本?

flutter - Dart 删除方括号并添加单引号

dart - 在Dartium中使用铯

flutter - 什么时候 route.didPop(result) 在 Flutter Navigator 2.0 中等于 false

flutter - 为什么我从负数的模数运算中得到不正确的输出

android - flutter 页面浏览量 : Find first and last page and swipe directions

database - Flutter Firebase数据库 “The method ' forEach'被调用为null。”

Flutter 文本颜色主题在 ListTile 标题下不起作用

android - Flutter中的汇率货币格式设置