0

我有两个 StreamBulder First Stream in collection("Users").document("PhoneNum") 是内容名称和照片。sec Stream in Collection("Users").document("PhoneNum").document("FrindList") 这是我想让第一个 Stream 获得我不想为所有人构建 Stream 的所有结果的 Frind PhoneNumber FrindList 获取名称和照片并将其放入 ListView

我尝试了很多代码,但它不起作用

我试着做这样

StreamBuilder(
  stream: Firestore.instance.collection("Users")
      .document(names)
      .snapshots(),
  builder: (context, snapshot) {
    if (!snapshot.hasData) {
      return CircularProgressIndicator(
        backgroundColor: Colors.white,
      );
    } else {
      List<Widget> list = [];
      var Frindname = snapshot.data["name"];
      var Frindpic = snapshot.data["ImageURL"];
      var Frindnum = snapshot.data["PhoneNumber"];
      try {

         return GestureDetector(
            onTap: () {
              var chatkey;
              if (widget.phoneN.compareTo(Frindnum) >
                  0) {
                chatkey = widget.phoneN + Frindnum;
                print(chatkey);
              } else {
                chatkey = Frindnum + widget.phoneN;
                print(chatkey);
              }

              Navigator.push(context,
                  MaterialPageRoute(
                      builder: (context) {
                        return Chat();
                      }));
            },
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.vertical(
                    bottom: Radius.elliptical(
                        100, 100),
                    top: Radius.elliptical(100, 100)),
                color: Colors.grey[200],),
              padding: EdgeInsets.all(20),
              child: Row(
                children: <Widget>[
                  CircleAvatar(
                    backgroundImage: NetworkImage(
                        Frindpic), radius: 30,),
                  SizedBox(width: 10,),
                  Text(Frindname, style: TextStyle(
                      color: Colors.deepPurple,
                      fontSize: 18,
                      fontWeight: FontWeight.bold),),
                ],
              ),
            ),

        );


      } catch (e) {
        return CircularProgressIndicator(
          backgroundColor: Colors.white,);
      }
    }
  },

);

然后在其他流构建器中调用此方法

StreamBuilder<QuerySnapshot>(
                stream: Firestore.instance.collection("Users").document(widget.phoneN).collection("FrindList").snapshots(),
                builder: (context, snapshot) {
                  if (!snapshot.hasData) {
                    CircularProgressIndicator(
                      backgroundColor: Colors.white,
                    );
                  }
                    try {
                    List<Widget> e = [];
                    snapshot.data.documents.forEach((d) {
                      print(d.data["FrindKey"]);
                      e.add(Streems(d.data["FrindKey"]));
                    }

                    );
                   return ListView(
                     children: e,
                   );

                     } catch (e) {
                      print(e);
                      return Text("No Friend Found", style: TextStyle(
                          color: Colors.deepPurple,
                          fontSize: 24,
                          fontWeight: FontWeight.bold),);
                    }
                  }

                 ),

这是我的数据库结构

数据库结构

4

1 回答 1

0

它是由 listview.builder 中使用的 sec streambuilder 解决的,它从第一个 streambuilder 返回,它给出了用户列表,sec streambuilder 将根据第一个流的结果获得详细信息

于 2019-06-13T04:33:09.697 回答