这个问题在这里已经有了答案:
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/