【问题标题】:how do i load an array from firestore to a list in flutter?如何将数组从firestore加载到flutter中的列表?
【发布时间】:2020-08-26 15:33:02
【问题描述】:
【问题讨论】:
标签:
flutter
dart
flutter-listview
【解决方案1】:
希望您使用模型反序列化?
给你一个示范食谱的例子
class Recipe {
final String name;
final List<String> ingredients;
final List<String> preparation;
Recipe({this.name, this.ingredients, this.preparation});
factory Recipe.fromDocument(DocumentSnapshot doc){
return Recipe(
name: doc["name"],
ingredients: doc["ingredients"],
preparation : doc["preparation"]);
}
因此,在您的 FutureBuilder 中,您可以迭代并调用 Recipe.fromDocument 工厂方法并将文档作为参数。