gpt4 book ai didi

firebase - 在 Flutter 中从 Firebase 读取数组

转载 作者:行者123 更新时间:2023-12-02 07:19:07 28 4
gpt4 key购买 nike

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





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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com