firebase - Firestore 返回列表而不是列表(扑)
问题描述
我有一个使用字符串数组设置的 firestore 数据库。在我的代码中,我有这个:
factory Item.fromMap(Map<String, dynamic> map) {
return Item(
name: map['name'],
imageUrls: map['imageUrls'];
imageUrls 是一个字符串列表。我用谷歌搜索了如何处理列表,但我认为它应该能够像这样处理它?我收到此错误:
Expected a value of type List<String>, but got one of type List<dynamic>
感谢您的任何输入
解决方案
您必须将 map['imageUrls'] 转换为 List
factory Item.fromMap(Map<String, dynamic> map) {
return Item(
name: map['name'],
imageUrls: (map['imageUrls'] as List)?.map((item) => item as String)?.toList();
推荐阅读
- r - 如何从`sf::st_layers()`中提取层的名称?
- c# - 如何使用 JQuery dataicker 在 asp.net c# 中更改日期格式
- c - 是否有一个属性告诉编译器忽略缺少的返回语句?
- javascript - Node.js - 循环读取和写入数千/数百万个 JSON 文件
- utf-8 - Windows Server 2012 r2 中所有应用程序的活动代码页更改?
- php - 更新表单值不起作用 yii2
- python - 如何使用 .csv 文件在 Django 中填充多对多字段?
- jquery - 即使使用引号,JQuery 也无法正确读取值
- angular - 哪些因素会影响产品的捆绑大小以及编译和构建以组织以下场景?
- amazon-s3 - 如何在 python 中解析 xml S3 存储桶