【问题标题】:how do i load an array from firestore to a list in flutter?如何将数组从firestore加载到flutter中的列表?
【发布时间】:2020-08-26 15:33:02
【问题描述】:

我是 Flutter 的新手,我正在创建一个食谱应用程序。如图所示,我的成分存储为数组。我想知道如何将它们加载到列表中以在我的食谱详细信息页面上显示它们。enter image description here

【问题讨论】:

标签: 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 工厂方法并将文档作为参数。

【讨论】:

    猜你喜欢
    • 2021-01-24
    • 1970-01-01
    • 2020-08-06
    • 2018-11-21
    • 1970-01-01
    • 2021-05-24
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多