Android DropdownButton未通过在颤振中选择值进行更新

Android DropdownButton未通过在颤振中选择值进行更新,android,flutter,Android,Flutter,每当我尝试将值更新为所需值时,它都不会改变 以下是相关代码的片段: new DropdownButton<String>( items: <String>['A', 'B', 'C', 'D'].map((String value) { return new DropdownMenuItem<String>( value: value, chil

每当我尝试将值更新为所需值时,它都不会改变

以下是相关代码的片段:

new DropdownButton<String>(
            items: <String>['A', 'B', 'C', 'D'].map((String value) {
              return new DropdownMenuItem<String>(
                value: value,
                child: new Text(value),
              );
            }).toList(),
              onChanged: (value) {
                setState(() {
                  value1 = value!;
                });
              }
          )
新建下拉按钮(
项目:['A','B','C','D'].map((字符串值){
返回新的DropdownMenuItem(
价值:价值,
子项:新文本(值),
);
}).toList(),
一旦更改:(值){
设置状态(){
value1=值!;
});
}
)

问题似乎在于,您正在setState中更新的变量名为value1,而您在DropdownMenuItem中分配给value参数的变量名为value1

尝试对onChanged使用以下代码:

onChanged: (newValue) {
            setState(() {
              value = newValue;
            });
          }