[英]Flutter - How to show ArrayList items pulled from Firebase Firestore with ListTile?
I have a build on Firebase Firestore like this:我在 Firebase Firestore 上构建如下:
In the structure here, there are 2 ArrayLists.在这里的结构中,有2个ArrayList。 I want to display what will be done from 2 ArrayLists as
ListTile
.我想将 2 个 ArrayLists 的操作显示为
ListTile
。
I tried a code like this:我试过这样的代码:
Expanded(
child: StreamBuilder <QuerySnapshot>(
stream: FirebaseFirestore.instance.collection("users").doc(FirebaseAuth.instance.currentUser.uid).collection("yapilacaklar").snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return Expanded(
child: _buildList(snapshot.data),
);
},
)
),
Widget _buildList(QuerySnapshot snapshot) {
return ListView.builder(
itemCount: snapshot.docs.length,
itemBuilder: (context, index) {
final doc = snapshot.docs[index];
return ListTile(
title: Text(doc["yapilacaklar"].toString()),
);
},
);
}
These codes I tried do not give an error, but they do not show in any Widget.我试过的这些代码没有给出错误,但它们没有显示在任何 Widget 中。 How can I do what I want?
我怎样才能做我想做的事? Thanks in advance for the help.
先谢谢您的帮助。
I believe the issue is the '.collection("yapilacaklar")'.我认为问题在于“.collection("yapilacaklar")”。 It will try to find a collection with the id "yapilacaklar" and your user doc doesn't have any collections. Yapilacaklar, in this case, is a field in the document.
它将尝试查找 ID 为“yapilacaklar”的集合,而您的用户文档没有任何 collections。在这种情况下,Yapilacaklar 是文档中的一个字段。 Try getting the snapshots of the actual document and then creating a ListView from the array in the yapilacaklar field.
尝试获取实际文档的快照,然后从 yapilacaklar 字段中的数组创建一个 ListView。
The flutterfire documentation is very helpful for reading firestore data: https://firebase.flutter.dev/docs/firestore/usage/#read-data flutterfire 文档对于读取 firestore 数据非常有帮助: https://firebase.flutter.dev/docs/firestore/usage/#read-data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.