Flutter 清除下拉按钮抖动

Flutter 清除下拉按钮抖动,flutter,Flutter,我有一个下拉按钮,可以为我的产品添加类别。添加产品后,单击下拉按钮显示我选择的类别。添加产品后,我想刷新或清除下拉按钮。最好显示提示文本 代码: child: StreamBuilder<List<Categories>>( stream: categories, builder: ((context, snapshot) {

我有一个
下拉按钮
,可以为我的产品添加类别。添加产品后,单击下拉按钮显示我选择的类别。添加产品后,我想刷新或清除
下拉按钮
。最好显示提示文本

代码:

 child: StreamBuilder<List<Categories>>(
                              stream: categories,
                              builder: ((context, snapshot) {
                                if (!snapshot.hasData)
                                  return CircularProgressIndicator();
                                return DropdownButton(
                                  hint: Text('choose category'),
                                  value: _currentCategory,
                                  items: snapshot.data
                                      .map((doc) => DropdownMenuItem(
                                            child: Text(doc.categoryname),
                                            value: doc,
                                          ))
                                      .toList(),
                                  onChanged: (selectedCategory) =>
                                      setState(() {
                                    _currentCategory = selectedCategory;
                                  }),
                                );
                              })),
                        ),
                        SizedBox(height: 15),
                        RaisedButton(
                          onPressed: () {
                            if (_formKeyProduct.currentState.validate()) {
                              ProductService().addProduct(
                                  _nameproductController.text,
                                  _priceproductController.text,
                                  _currentCategory.categoryname.toString());
                              _formKeyProduct.currentState.reset();
                              _nameproductController.clear();
                              _priceproductController.clear();
                            }
                          },
                          child: Text('add product'),
child:StreamBuilder(
流:类别,
生成器:((上下文、快照){
如果(!snapshot.hasData)
返回循环ProgressIndicator();
返回下拉按钮(
提示:文本(“选择类别”),
值:_currentCategory,
项目:snapshot.data
.map((doc)=>下拉菜单项(
子项:文本(doc.categoryname),
价值:doc,
))
.toList(),
一旦更改:(selectedCategory)=>
设置状态(){
_currentCategory=selectedCategory;
}),
);
})),
),
尺寸箱(高度:15),
升起的按钮(
已按下:(){
if(_formKeyProduct.currentState.validate()){
ProductService().addProduct(
_nameproductController.text,
_priceproductController.text,
_currentCategory.categoryname.toString());
_formKeyProduct.currentState.reset();
_nameproductController.clear();
_priceproductController.clear();
}
},
子项:文本(“添加产品”),

因为您选择的值是
\u currentCategory
使用

setState(() {
    _currentCategory = null;
  }
)

应该这样做。

那么您当前的问题是什么?单击“添加产品”时,表单字段被清除,但dropdownbutton仍显示我选择的类别您想在选择项目后删除dropdownbutton中的所有项目吗?是的,在我单击“添加产品”按钮后删除,并将其放入RaisedButton
onPressed()中
。这有点含蓄,但确实如此