Android 颤振-如何从静态列表中动态下拉?
我有一个名为getbride()的方法,根据另一个小部件中填充的物种,返回狗或猫的品种列表,以填充品种的动态下拉列表。但此方法工作不正常,出现错误: 对null调用了方法“map”。尝试调用:map>(闭包:(字符串)=>DropdownMenuItem) 但是,如果我调用直接返回列表的方法,它就会工作,例如:Android 颤振-如何从静态列表中动态下拉?,android,ios,flutter,dart,Android,Ios,Flutter,Dart,我有一个名为getbride()的方法,根据另一个小部件中填充的物种,返回狗或猫的品种列表,以填充品种的动态下拉列表。但此方法工作不正常,出现错误: 对null调用了方法“map”。尝试调用:map>(闭包:(字符串)=>DropdownMenuItem) 但是,如果我调用直接返回列表的方法,它就会工作,例如: //instead of this DropdownContent.getBreed(widget.pet.specie).map<DropdownMenuItem<Stri
//instead of this
DropdownContent.getBreed(widget.pet.specie).map<DropdownMenuItem<String>>((String value) {
//i put this
DropdownContent.listOfDogBreeds().map<DropdownMenuItem<String>>((String value) {
//而不是这个
DropdownContent.getbride(widget.pet.specie).map((字符串值){
//我把这个
DropdownContent.ListofDogBrides().map((字符串值){
为什么会这样?下面是我的全部代码:
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new DropdownButton<String>(
value: widget.pet.breed == null
? dropdownInitialValue
: widget.pet.breed,
icon: Icon(Icons.arrow_downward),
iconSize: 15,
elevation: 16,
style: TextStyle(color: Colors.black, fontSize: 14),
underline: Container(
height: 2,
color: Colors.grey,
),
onChanged: (String newValue) {
setState(() {
dropdownInitialValue = newValue;
widget.pet.breed = newValue;
});
},
items: DropdownContent.getBreed(widget.pet.specie).map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)
])
class DropdownContent {
static List<String> listOfDogBreeds() {
return [
'Select',
'Australian Cattle',
'Basset Hound',
'Chihuahua',
'Chow Chow'
];
}
static List<String> listOfCatBreeds() {
return <String>[
'Select',
'American Shorthair',
'Bengal',
'Maine Coon',
'Sphynx'
];
}
static getBreed(String specie) {
if (specie.contains('dog')) {
listOfDogBreeds();
}
if (specie.contains('cat')) {
listOfCatBreeds();
}
}
}
新行(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
新下拉按钮(
值:widget.pet.bride==null
?下拉初始值
:widget.pet.breed,
图标:图标(图标。向下箭头),
iconSize:15,
海拔:16,
样式:TextStyle(颜色:Colors.black,字体大小:14),
下划线:容器(
身高:2,
颜色:颜色。灰色,
),
onChanged:(字符串newValue){
设置状态(){
dropdownInitialValue=新值;
widget.pet.bride=newValue;
});
},
条目:DropdownContent.getbride(widget.pet.specie).map((字符串值){
返回下拉菜单项(
价值:价值,
子项:文本(值),
);
}).toList(),
)
])
类下拉内容{
静态列表ListOfDogBurds(){
返回[
“选择”,
“澳大利亚牛”,
“巴塞特猎犬”,
“吉娃娃”,
“Chow Chow”
];
}
静态列表listofcatbrides(){
返回[
“选择”,
“美国短发”,
“孟加拉”,
“缅因州库恩”,
“斯芬克斯”
];
}
静态getBreed(字符串种类){
如果(物种包含('dog')){
ListofDoggrieds();
}
如果(物种包含('cat')){
Listofcatbrides();
}
}
}
在“getbride”方法中缺少单词return,在“getbride”方法中的“return”关键字在哪里?它起作用了!你是对的,“getbride”方法中的“return”关键字丢失了。请写下你的评论作为答案,以便我可以批准。非常感谢你