[英]dont have access in docs while using streamBuilder. Firebase Flutter
when i try to use snapshot i dont have access to the document please check code you will understand.当我尝试使用快照时,我无法访问该文档,请检查您会理解的代码。
Widget build(BuildContext context) {
return StreamBuilder(
stream: FirebaseFirestore.instance.collection('chat').snapshots(),
builder: (context, snapshot) {
return snapshot.connectionState == ConnectionState.waiting
? const CircularProgressIndicator()
: ListView.builder(
itemCount: 2,
itemBuilder: (context, index) => BubbleNormal(
text: snapshot.data. // in here i can't do snapshot.data.docs,
),
);
});
}
As shown in the documentation on monitoring realtime changes , you'll want to declare the type of your StreamBuilder
:如有关监视实时更改的文档中所示,您需要声明
StreamBuilder
的类型:
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('chat').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.