[英]Get selected text from a drop-down menu (Flutter)
Im already getting the value and using it to add an total item price is it possible to get the selected text from a drop down menu and add it to an array list?我已经获得了价值并使用它来添加总商品价格是否可以从下拉菜单中获取所选文本并将其添加到数组列表中?
Here is how im creating my MenuItems from firestore.这是我如何从 Firestore 创建我的 MenuItems。
final itemExtras = snap.data.documents[i]['op'];
for (var extra in itemExtras) {
if (extra['add'] > 0) {
items.add(
DropdownMenuItem(
child: Text(
extra['name'] +
' + Bs. ' +
extra['add']
.toString(),
style: TextStyle(
fontWeight:
FontWeight.bold),
),
value: extra['add'],
),
);
}
and this is the button这是按钮
DropdownButton(
isExpanded: true,
items: items,
style: Theme.of(context)
.textTheme
.title,
onChanged: (selectedValue) {
setState(() {
dropdownValues[i] =
selectedValue;
addPrice =
dropdownValues.fold(
0,
(previous,
current) =>
previous +
current);
total = (addPrice +=
widget.snapshot[
'price']);
});
print(dropdownValues
.toString() +
index.data.toString());
},
hint: Text('Select Extra'),
value: dropdownValues[i],
)
i need to get the extra['name']我需要得到额外的['name']
将您的DropdownMenuItem.value
更改为extra
,而不是extra['add']
,然后它将是selectedValue
的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.