[英]Listen to two collections in firestore database from flutter
我一直在尝试聆听两种不同的收藏文件。 一个如下所示。 它基本上是将实时数据写入屏幕。 我也想听其他集合,但改为执行特定的 function。 请问我该怎么办? 非常感谢任何帮助!
Expanded(
child: StreamBuilder(
stream:
FirebaseFirestore.instance.collection('location').snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
return ListView.builder(
itemCount: snapshot.data?.docs.length,
itemBuilder: (context, index) {
return ListTile(
title:
Text(snapshot.data!.docs[index]['name'].toString()),
subtitle: Row(
children: [
Text(snapshot.data!.docs[index]['latitude']
.toString()),
SizedBox(
width: 20,
),
Text(snapshot.data!.docs[index]['longitude']
.toString()),
],
),
trailing: IconButton(
icon: Icon(Icons.directions),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) =>
MyMap(snapshot.data!.docs[index].id)));
},
),
);
});
},
)),
您可以收听其他 firebase collections 并像这样调用您的函数。
FirebaseFirestore.instance
.collection('location')
.snapshots()
.listen((QuerySnapshot querySnapshot) {
final firestoreList = querySnapshot.docs;
print(firestoreList.first.data());
}).onError((e) => print(e));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.