Flutterの下記のようなコードでFirebaseのFirestoreのsnapshotsを取得し、ListView.builderの中で参照型のデータを取得する場合どのように行えばよいでしょうか?
イメージとして、commentsというcollectionsに対して、authorという投稿者のcollectionsを参照型で定義しているような感じです。
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('comments')
.snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator(),
);
}
if (snapshot.hasError) {
return const Text('Error..');
}
return ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (BuildContext context, int index) {
final comment = snapshot.data!.docs[index];
// comment['author'](参照型)のデータを取得したい
return Text(comment.id.toString());
});
});