简体   繁体   English

使用 streamBuilder 时无权访问文档。 Firebase Flutter

[英]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,
              ),
            );
    });
}

1 please check the image more helpful 1请检查图像更有帮助

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM