Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:我的下拉按钮值没有被接受?_Flutter_Google Cloud Firestore - Fatal编程技术网

Flutter 颤振:我的下拉按钮值没有被接受?

Flutter 颤振:我的下拉按钮值没有被接受?,flutter,google-cloud-firestore,Flutter,Google Cloud Firestore,我在使用DropdownButton时遇到了一个问题,我的价值没有被采纳 是空的吗 我的代码在下面 SizedBox( height: 60.0, child: new StreamBuilder<QuerySnapshot>( stream: Firestore.instance.collection("Category").snapshots(),

我在使用DropdownButton时遇到了一个问题,我的价值没有被采纳

是空的吗

我的代码在下面

 SizedBox(
              height: 60.0,
              child:  new StreamBuilder<QuerySnapshot>(
                  stream: Firestore.instance.collection("Category").snapshots(),
                  builder: (context, snapshot) {
                    if (!snapshot.hasData) return new Text("Please wait");
                    var length = snapshot.data.documents.length;
                    DocumentSnapshot ds = snapshot.data.documents[length - 1];
                    return new DropdownButton(
                        items: snapshot.data.documents.map((
                            DocumentSnapshot document) {
                          return DropdownMenuItem(
                              child: new Text(document.data["name"]));
                        }).toList(),
                        value: category,
                        onChanged: (value) {
                          print(value);
                        },
                        hint: new Text("Category"),
                        style: TextStyle(color: Colors.black),

                    );
                  }
              ),
            ),
SizedBox(
身高:60.0,
孩子:新的StreamBuilder(
流:Firestore.instance.collection(“Category”).snapshots(),
生成器:(上下文,快照){
如果(!snapshot.hasData)返回新文本(“请稍候”);
var length=snapshot.data.documents.length;
DocumentSnapshot ds=snapshot.data.documents[length-1];
返回新的下拉按钮(
项目:snapshot.data.documents.map((
文档(快照文档){
返回下拉菜单项(
子项:新文本(document.data[“name”]);
}).toList(),
值:类别,
一旦更改:(值){
印刷品(价值);
},
提示:新文本(“类别”),
样式:TextStyle(颜色:Colors.black),
);
}
),
),

您应该阅读更多关于StatefulWidget的信息,这里有文档:

要解决问题,只需更新类别变量并刷新状态

更新

看起来您也忘记了项目的值

    SizedBox(
                  height: 60.0,
                  child:  new StreamBuilder<QuerySnapshot>(
                      stream: Firestore.instance.collection("Category").snapshots(),
                      builder: (context, snapshot) {
                        if (!snapshot.hasData) return new Text("Please wait");
                        var length = snapshot.data.documents.length;
                        DocumentSnapshot ds = snapshot.data.documents[length - 1];
                        return new DropdownButton(
                            items: snapshot.data.documents.map((
                                DocumentSnapshot document) {
                              return DropdownMenuItem(
                                  value: document.data["name"],
                                  child: new Text(document.data["name"]));
                            }).toList(),
                            value: category,
                            onChanged: (value) {
                              print(value);

                               setState(() {
                                  category = value;
                                });
                            },
                            hint: new Text("Category"),
                            style: TextStyle(color: Colors.black),

                        );
                      }
                  ),
                ),
SizedBox(
身高:60.0,
孩子:新的StreamBuilder(
流:Firestore.instance.collection(“Category”).snapshots(),
生成器:(上下文,快照){
如果(!snapshot.hasData)返回新文本(“请稍候”);
var length=snapshot.data.documents.length;
DocumentSnapshot ds=snapshot.data.documents[length-1];
返回新的下拉按钮(
项目:snapshot.data.documents.map((
文档(快照文档){
返回下拉菜单项(
值:document.data[“name”],
子项:新文本(document.data[“name”]);
}).toList(),
值:类别,
一旦更改:(值){
印刷品(价值);
设置状态(){
类别=价值;
});
},
提示:新文本(“类别”),
样式:TextStyle(颜色:Colors.black),
);
}
),
),

您能为我们提供更多信息吗?你的下拉列表更新了吗?是的,我得到了列表。只有一个人认为我不能得到onchange值…而且提示没有显示。我的意思是重建小部件,使用setState((){});当我在控制台中选择一个名称为show me null时,请检查我的更新答案:DropdownMenuItem,,,您忘记了属性值。别担心,继续浮动!!:)