【发布时间】:2020-11-08 01:28:18
【问题描述】:
这里我有从 Firebase 检索所有文档的代码,我只能检索文档中存在的数据,但我也想用它检索文档 ID,我该怎么做?
StreamBuilder<QuerySnapshot>(
stream: getData(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return new Text('Loading...');
default:
return new ListView(
children: snapshot.data.documents
.map((DocumentSnapshot document) {
return new CustomCard(
name: document['name'],
phone: document['phno'],
service: document['Category'],
address: document['address'],
pin: document['pin'],
payment: document['Payment'],
);
}).toList(),
);
}
},
),
这是我的getter函数
Stream<QuerySnapshot> getData()async*{
FirebaseUser user = await FirebaseAuth.instance.currentUser();
yield* Firestore.instance
.collection('User')
.where("userId", isEqualTo: user.uid)
.orderBy('upload time', descending: true)
.snapshots();
}
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore flutter-dependencies