【问题标题】:how to display a custom list data on the app page in flutter如何在flutter的应用页面上显示自定义列表数据
【发布时间】:2020-06-01 11:19:42
【问题描述】:

1[https://i.stack.imgur.com/yI2Cp.png">]1

我已尝试使用此代码从存储在许多 firebase 文档中的同名(userProducts)子集合中检索数据。如何在应用页面的容器中显示此数据?我尝试使用 listiew.builder 但它不起作用。 第一个函数

 static List<products> finalProductsList = [] ;
  productsList() async
  {
    List list_of_products = await Firestore.instance.collection("products")
        .getDocuments()
        .then((val) => val.documents);
    for (int i=0; i<list_of_products.length; i++)
    {
      Firestore.instance.collection("products").document(
          list_of_products[i].documentID.toString()).collection("userProducts").snapshots().listen(CreateListofProducts);
    }
  }

第二个功能

 CreateListofProducts(QuerySnapshot snapshot)async
  {
    var docs = snapshot.documents;
    for (var Doc in docs)
    {
      finalProductsList.add(products.fromFireStore(Doc));
    }
    }

课程模型

class products {
  final String prodId;
  final String ownerId;
  final String username;
  final String price;
  final String productname;
  final String details;
  final String color;
  final String composition;
  final String washandcare;
  final String sizeandfit;
  final String shopmediaUrl;
  final String id;
  final dynamic likes;
  products({ this.prodId,
    this.ownerId,
    this.username,
    this.price,
    this.details,
    this.productname,
    this.color,
    this.composition,
    this.washandcare,
    this.sizeandfit,
    this.shopmediaUrl,
    this.id,
    this.likes,});

  factory products.fromFireStore(DocumentSnapshot doc)
  {
    Map data = doc.data ;
    return products(
      prodId: doc['prodId'],
      ownerId: doc['ownerId'],
      username: doc['username'],
      price: doc['price'],
      productname: doc['productname'],
      details: doc['details'],
      shopmediaUrl: doc['shopmediaUrl'],
      color:doc['color'],
      composition:doc['composition'],
      washandcare:doc['washandcare'],
      sizeandfit:doc['sizeandfit'],
      likes: doc['likes'],
    );

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore


    【解决方案1】:

    如果我理解你的话,你想获取多个文档的多个集合的数据吗?

    如果是这样...你应该使用collecionGroup,你可以学习如何使用here,确保调整你的firestore规则。

    【讨论】:

    • 不,我已经编辑了图像和代码。看看你现在能不能理解。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 2019-03-25
    相关资源
    最近更新 更多