Flutter Simulator 在使用来自 firebase 集合的值的下拉列表时出错

问题描述

谁能帮我解决这个错误。我的应用程序中有一个下拉菜单,它从 firebase 集合中获取菜单项。此错误仅出现在模拟器中,需要有关此方面的帮助。有时它有效,有时它会出错。对此的任何解决方案。 Android 和 iOS 均存在此错误。

这是我的下拉菜单代码,它从 firebase 集合中获取项目

            Container(
        padding: EdgeInsets.all(10.0),child: StreamBuilder<QuerySnapshot>(
          stream: FirebaseFirestore.instance.collection("test").snapshots(),builder: (context,snapshot) {
            if (!snapshot.hasData)
              const Text("Loading");
            else {
              List<DropdownMenuItem> occupationItems = [];
              for (int i = 0; i < snapshot.data.docs.length; i++) {
                DocumentSnapshot snap = snapshot.data.docs[i];
                occupationItems.add(
                  DropdownMenuItem(
                    child: Text(
                      snap.id,style: TextStyle(color: Colors.black),),value: "${snap.id}",);
              }
              return DropdownButtonFormField(
                validator: (value) =>
                    value.isEmpty ? 'Select your occupation' : null,decoration: InputDecoration(
                  border: InputBorder.none,icon: FaIcon(
                  FontAwesomeIcons.chevronCircleDown,color: Colors.grey,size: 20.0,items: testItems,onChanged: (testValue) {
                  setState(
                    () {
                      test = testValue;
                    },);
                },value: test,hint: Text(
                  "test",style: TextStyle(
                    color: Colors.grey,);
            }
          },

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)