如何在Firestore中继续下拉菜单选择

时间:2019-09-17 09:17:50

标签: flutter dart drop-down-menu google-cloud-firestore

在下拉菜单中选择第一个选项时,我正在尝试选择Firestore数据库的下一部分。我希望这样,以便在选择地点时可以显示该类别的值。

我试图继续选择,但是即使数据库中有数据,它也会一直给我一个空响应

StreamBuilder<QuerySnapshot>(
              stream:
              Firestore.instance.collection('clubDropDownMenu').snapshots(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Text('Loading...');
                } else {
                  List<DropdownMenuItem> clubLocations = [];
                  for (int i = 0; i < snapshot.data.documents.length; i++) {
                    DocumentSnapshot ds = snapshot.data.documents[i];
                    clubLocations.add(DropdownMenuItem(
                      child: Text(
                        ds.documentID,
                        style: TextStyle(color: Colors.black),
                      ),
                      value: '${ds.documentID}',
                    ));
                  }
                  return Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      DropdownButton(
                        items: clubLocations,
                        onChanged: (locationValue) {
                          final snackBar = SnackBar(
                            content: Text(
                              'Selected Location is $locationValue',
                              style: TextStyle(color: Colors.black),
                            ),
                          );
                          Scaffold.of(context).showSnackBar(snackBar);
                          this.setState(() {
                            _selectedLocation = locationValue;
                          });
                        },
                        value: _selectedLocation,
                        isExpanded: false,
                        hint: new Text(
                          'Choose Location',
                          style: TextStyle(color: Colors.black),
                        ),
                      ),
                    ],
                  );
                }
              },
            ),
            SizedBox(height: 8.0),
            StreamBuilder<QuerySnapshot>(
              stream: Firestore.instance.collection('dropDownMenu').snapshots(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Text('Loading...');
                } else {
                  List<DropdownMenuItem> clubDisciplines = [];
                  for (int i = 0; i < snapshot.data.documents.length; i++) {
                    DocumentSnapshot ds = snapshot.data.documents[i];
                    clubDisciplines.add(DropdownMenuItem(
                      child: Text(
                        ds.documentID,
                        style: TextStyle(color: Colors.black),
                      ),
                      value: '${ds.documentID}',
                    ));
                  }
                  return Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      DropdownButton(
                        items: clubDisciplines,
                        onChanged: (disciplineValue) {
                          final snackBar = SnackBar(
                            content: Text(
                              'Selected Discipline is $disciplineValue',
                              style: TextStyle(color: Colors.black),
                            ),
                          );
                          Scaffold.of(context).showSnackBar(snackBar);
                          this.setState(() {
                            _selectedDiscipline = disciplineValue;
                          });
                        },
                        value: _selectedDiscipline,
                        isExpanded: false,
                        hint: new Text(
                          'Choose Discipline',
                          style: TextStyle(color: Colors.black),
                        ),
                      ),
                    ],
                  );
                }
              },
            ),
            SizedBox(height: 8.0),
            StreamBuilder<QuerySnapshot>(
              stream: Firestore.instance.collection('dropDownMenu').snapshots(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Text('Loading...');
                } else {
                  List<DropdownMenuItem> clubLevels = [];
                  for (int i = 0; i < snapshot.data.documents.length; i++) {
                    DocumentSnapshot ds = snapshot.data.documents[i];
                    clubLevels.add(DropdownMenuItem(
                      child: Text(
                        ds.documentID,
                        style: TextStyle(color: Colors.black),
                      ),
                      value: '${ds.documentID}',
                    ));
                  }
                  return Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      DropdownButton(
                        items: clubLevels,
                        onChanged: (levelValue) {
                          final snackBar = SnackBar(
                            content: Text(
                              'Selected Level is $levelValue',
                              style: TextStyle(color: Colors.black),
                            ),
                          );
                          Scaffold.of(context).showSnackBar(snackBar);
                          this.setState(() {
                            _selectedLevel = levelValue;
                          });
                        },
                        value: _selectedLevel,
                        isExpanded: false,
                        hint: new Text(
                          'Choose Level',
                          style: TextStyle(color: Colors.black),
                        ),
                      ),
                    ],
                  );
                }
              },
            ),

这是我设法开始工作的代码,但是当我选择第一个实例时,第二个实例不会出现。我已将代码还原回去,因此我可以运行该应用程序,我只需要选择第一类的帮助,然后便会看到可用的选项,对任何帮助都非常感谢

0 个答案:

没有答案