即使条件失败也接收到数据,使嵌套的StreamBuilder浮动以进行基于对象的过滤

时间:2019-05-01 11:49:36

标签: firebase flutter google-cloud-firestore

我在Cloud Firestore中有一个Matrimony用户数据库,我希望非注册用户能够注册,然后由人类验证注册用户,然后在ListTile中能够验证异性婚姻帐户的已验证用户超过堆栈。

Widget NameTile(AsyncSnapshot<dynamic> snapshot) {
    if(!snapshot.hasData) {
                    return CircularProgressIndicator();
                  }
                  else {
                    return ListView.builder(
                      itemCount: snapshot.data.documents.length,
                      //reverse: true,
                      //controller: _scrollController,
                      itemBuilder: (context, index){
                        return Card(
                          elevation: 8.0,
                          margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
                          child: Container(
                            decoration: BoxDecoration(color: Colors.white),
                            child: ListTile(
                              contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),

                          //     leading: CircleAvatar(
                          //     backgroundImage: NetworkImage(snapshot.data.documents[index].data['image']),
                          // ),

                          title: Text(
                            snapshot.data.documents[index].data['name'],
                            style:  Theme.of(context).textTheme.headline,
                            textAlign: TextAlign.center,
                          ),


                            // subtitle: Text("Intermediate", style: TextStyle(color: Colors.white)),
                            trailing:
                              Icon(Icons.keyboard_arrow_right, color: Colors.orangeAccent[700], size: 30.0),

                             //onTap: () => navigateToDetail(snapshot.data.documents[index]),

                            ),
                          ),
                        );
                      },
                    );
                  }
  }
StreamBuilder(
                stream: Firestore.instance.collection("Matrimonial").where("email", isEqualTo: _userEmail).limit(1).snapshots(),
                builder: (context, snapshot) {
                  if(snapshot.hasData)
                  {
                    return StreamBuilder(
                      stream: Firestore.instance.collection("Matrimonial").where("email", isEqualTo: _userEmail).where("verify", isEqualTo: 1).limit(1).snapshots(),
                      builder: (context, snapshot) {
                        if(snapshot.hasData)
                        {
                          return StreamBuilder(
                            stream: Firestore.instance.collection("Matrimonial").where("verify", isEqualTo: 1).where("email", isEqualTo: _userEmail).where("gender", isEqualTo: 'm').limit(1).snapshots(),
                            builder: (context, snapshot) {
                              if(snapshot.hasData)
                              {
                                //show female
                                return StreamBuilder(
                                  stream: Firestore.instance.collection("Matrimonial").where("verify", isEqualTo: 1).where("gender", isEqualTo: 'f').snapshots(),
                                  builder: (context, snapshot) {
                                    return NameTile(snapshot);
                                  },
                                );
                              }
                              else
                              {
                                //show male
                                return StreamBuilder(
                                  stream: Firestore.instance.collection("Matrimonial").where("gender", isEqualTo: 'm').snapshots(),
                                  builder: (context, snapshot) {
                                      return NameTile(snapshot);
                                  },
                                );
                              }
                            },
                          );
                        }
                        else
                        {
                          //not verified
                          return Text("Wait, till verification");
                        }
                      },
                    )

当验证为0时,应显示“等待验证”,如果数据库中不存在电子邮件,则应显示“注册”。但是即使条件失败,它也会显示NameList小部件。

0 个答案:

没有答案