我正在使用dropbox,但我想做的是根据用户在dropbox上的选择来检索值;例如用户选择";苹果;在下拉框上,我想返回的是";维生素C";
以下是我目前所拥有的:
String myFruits;
List<String> fruits = [
"APPLE",
"ORANGE",
"BANANA",];
DropdownSearch(
onChanged: (dynamic value) {
myFruits = value;
},
mode: Mode.DIALOG,
items: fruits,
),
现在,当我打印myFruits时,它显示的是下拉框的选定值,我想要的是,如果选择苹果,它将返回";维生素c";就像那样。谢谢:(我怎样才能做到这一点?
您可以从水果和returnedValue中定义Map,例如:
Map<String, String> returnedValue = {
"APPLE" : "Vitamin A",
"ORANGE" : "Vitamin C",
"BANANA" : "Vitamin K",
};
并从此返回。
你所有的代码都是这样的:
Function(String) returnFunction();
String myFruits;
String myVitamin;
List<String> fruits = [
"APPLE",
"ORANGE",
"BANANA",
];
Map<String, String> returnedValue = {
"APPLE" : "Vitamin A",
"ORANGE" : "Vitamin C",
"BANANA" : "Vitamin K",
};
DropdownSearch(
onChanged: (dynamic value) {
myFruits = value;
myVitamin = returnedValue[value];
returenFunction(myVitamin); // if you want return from this class
},
mode: Mode.DIALOG,
items: fruits,
),