【问题标题】:Unhandled Exception: type 'List<String>' is not a subtype of type 'String' in type cast. What is the Solution for this?未处理的异常:类型 \'List<String>\' 不是类型转换中类型 \'String\' 的子类型。解决方案是什么?
【发布时间】:2022-12-05 13:30:01
【问题描述】:

我正在尝试将数据从包含列表和字符串类型的值的 flutter 代码传递到节点 api,但它给了我上述错误。解决方案是什么?

我在模型类中编写的代码是:

`

String? uid;
String? userName;
String? email;
List<String>? favDishes;

`

`

Map<String, dynamic> toMap(){
  return {`your text`
    "uid" : uid,
    "userName" : userName,
    "email" : email,
    "favDishes": favDishes
  };
}

`

【问题讨论】:

  • 添加更多代码,我们不能在此基础上说什么
  • 请提供足够的代码,以便其他人可以更好地理解或重现问题。

标签: flutter


【解决方案1】:

完毕... 问题出在我的 Api 中,而不是在这个类中。我的 Api 只接受字符串类型,所以我添加了 headers 字段,现在它表现完美。

【讨论】:

    猜你喜欢
    • 2019-08-03
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2021-01-28
    • 2021-02-09
    相关资源
    最近更新 更多