当我尝试更改下拉列表中的值时,它并没有在那一刻更改它的值,但是当我返回并再次打开对话框时,该更改将反映在过去两天的卡住中,请帮帮我。我检查了onChanged()是否正确调用,但是
value: currentMonth
在更改我关闭对话框并再次打开它时已调用的值后未调用。请帮帮我
下面是下拉代码
void _filterDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
child: Container(
width: 300,
height: 250,
child: Column(
children: <Widget>[
new Container(
child: new DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: currentMonth,
onChanged: (String newValue) {
setState(() {
currentMonth = newValue;
print(currentMonth);
});
},
items: <String>['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),),
)
],
),
),
);
});
}
在这里,我将currentMonth初始化为全局变量
String currentMonth = "";
我正在initState()中的currentMonth中填充值
@override
void initState() {
super.initState();
if (currentYear.month == 1) {
currentMonth = "January";
} else if (currentYear.month == 2) {
currentMonth = "February";
} else if (currentYear.month == 3) {
currentMonth = "March";
} else if (currentYear.month == 4) {
currentMonth = "April";
} else if (currentYear.month == 5) {
currentMonth = "May";
} else if (currentYear.month == 6) {
currentMonth = "June";
} else if (currentYear.month == 7) {
currentMonth = "July";
} else if (currentYear.month == 8) {
currentMonth = "August";
} else if (currentYear.month == 9) {
currentMonth = "September";
} else if (currentYear.month == 10) {
currentMonth = "October";
} else if (currentYear.month == 11) {
currentMonth = "November";
} else if (currentYear.month == 12) {
currentMonth = "December";
}
}