gpt4 book ai didi

firebase - 我可以使用此快照调用访问文档ID吗?

转载 作者:行者123 更新时间:2023-12-03 04:21:21 25 4
gpt4 key购买 nike

This is the streambuilder im using to access all the documents at once


 StreamBuilder(
stream: Firestore.instance.collection('projects').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Text('data is loading');
return ListView.builder(
itemBuilder: (ctx, index) {
return ProjectItem(
id: snapshot.data.documents[index]['id'],
title: snapshot.data.documents[index]['title'],
members: snapshot.data.documents[index]['members'],
complexity: snapshot.data.documents[index]['complexity'],
affordability: snapshot.data.documents[index]['affordability'],
duration: snapshot.data.documents[index]['duration'],
docid: snapshot.data.document[index].documentid,


);
},
itemCount: snapshot.data.documents.length,
}

Can i use docid: snapshot.data.document[index].documentid to access the document ids individually? if not whats the option? Thanks

最佳答案

您可以通过这种方式获取documentID

StreamBuilder(
stream: Firestore.instance.collection('projects').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Text('data is loading');
return ListView.builder(
itemBuilder: (ctx, index) {
QuerySnapshot snap = snapshot.data; // Snapshot
List<DocumentSnapshot> items = snap.documents; // List of Documents
DocumentSnapshot item = items[index]; Specific Document
return ProjectItem(
id: item.data['id'],
title: item.data['title'],
members: item.data['members'],
complexity: item.data['complexity'],
affordability: item.data['affordability'],
duration: item.data['duration'],
docid: item.documentID, // Document ID
);
},
itemCount: snapshot.data.documents.length,
);
},
),
)

关于firebase - 我可以使用此快照调用访问文档ID吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62482777/

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