Flutter 下拉选择不随颤振更改为当前值
我正在从Firestore获取物品,并在下拉列表中显示它们。当我从下拉列表中选择一个项目时,我会在控制台中打印选择,但所选项目不会更改。 Im使用map selectedValue[“add”]添加商品总价,使用selectedValue[“nom”]获取所选商品名称Flutter 下拉选择不随颤振更改为当前值,flutter,google-cloud-firestore,drop-down-menu,dropdown,Flutter,Google Cloud Firestore,Drop Down Menu,Dropdown,我正在从Firestore获取物品,并在下拉列表中显示它们。当我从下拉列表中选择一个项目时,我会在控制台中打印选择,但所选项目不会更改。 Im使用map selectedValue[“add”]添加商品总价,使用selectedValue[“nom”]获取所选商品名称 List<int> dropdownValues = []; Map opMap; List<DropdownMenuItem> items = []; final itemExtras = snap.
List<int> dropdownValues = [];
Map opMap;
List<DropdownMenuItem> items = [];
final itemExtras = snap.data.documents[i]['op'];
for (var extra in itemExtras) {
if (extra['add'] > 0) {
items.add(
DropdownMenuItem(
child: Text(
extra['nom'] +' + Bs. ' + extra['add'].toString(),
style: TextStyle(
fontWeight:
FontWeight.bold),
),
value: extra, //this is a map value
),
);
} else {
items.add(
DropdownMenuItem(
child: Text(
extra['nom'],
style: TextStyle(
fontWeight:
FontWeight.bold),),
value: extra,
),
);
}
}
))我认为,您可以更改该值,因为默认情况下它是一个完整的索引,您可以尝试以下方法:
int valueTemp;
DropdownButton(
isExpanded: true,
value: valueTemp,
item: item.map((val)=>DropdownMenuItem(
value: val.id,
child: Text(
val.description,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 16.0
),
)
)).toList(),
style: Theme.of(context)
.textTheme
.title,
onChanged: (selectedValue) {
setState(() {
valueTemp = selectedValue;
})
仍然卡住了,我在每个下拉按钮中使用mi firestore snapshot length生成的两个以上的值,这就是我需要返回映射值的方式。
int valueTemp;
DropdownButton(
isExpanded: true,
value: valueTemp,
item: item.map((val)=>DropdownMenuItem(
value: val.id,
child: Text(
val.description,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 16.0
),
)
)).toList(),
style: Theme.of(context)
.textTheme
.title,
onChanged: (selectedValue) {
setState(() {
valueTemp = selectedValue;
})