firebase - 在 Flutter 中从 Firebase 读取数组

标签 firebase dart google-cloud-firestore flutter

这个问题在这里已经有了答案:





How do you load array and object from Cloud Firestore in Flutter

(4 个回答)


3年前关闭。




我在 Firebase 中定义了一个具有不同字段类型的集合,例如字符串和字符串数组。

我可以从 DocumentSnapshot 读取字符串只需调用:

String name = document['name'];

但是我怎样才能得到List<String> ?通过调用
List<String> names1 = document['names'];
List<String> names2 = document['ingredients'].map((x) => x.toString())

我相应地得到以下异常(exception):

type 'List' is not a subtype of type 'List'
type 'MappedListIterable' is not a subtype of type 'List'

最佳答案

只需使用命名 .from 即可完成。构造函数:

List<String> names = List.from(document['names']);

关于firebase - 在 Flutter 中从 Firebase 读取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50891746/

相关文章:

flutter - Flutter:将Base64字符串图像url转换为File并在FileImage或相关小部件中使用

firebase - 如何在 flutter 中按日期将数据从 firestore 排序到 map

java - 从 Firebase 返回单个值

firebase - Flutter Dynamic Links 获取附加参数

android - Firebase 动态链接 - 打开应用的多个实例

dart - StageXL GraphicsGradient

swift - Firebase Firestore 时间戳至今问题

java - 使用 Firestore 管理 Android 后台堆栈和监听器以优化文档读取

java - FirebaseRecyclerAdapter 无法工作或显示任何数据

javascript - AngularFire 0.5.0 $on 'change' 事件未正确触发