flutter - i have an error : 'List>' is not a subtype of type 'List'
问题描述
I'm working on a flutter project where I pass an array of objects (List> array) to the stream-builder from my bloc. If I print the object, it prints nicely, but when I try to map them out in the DropdownMenuItem
, it throws me the mentioned error. Hence, if I create a dummy array in the same format within the class and access it, I do not get the error. I'm not sure what I am missing here.
Expanded(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: DropDownField(
controller: _idpatientController,
items: data.map<DropdownMenuItem<String>>((list) {
return DropdownMenuItem<String>(
child: Text(
list['nom_patient'] + " " + list['prenom_patient']),
value: list['id_patient'],
);
}).toList(),
value: selectedName,
onValueChanged: (value) {
setState(() {
selectedName = value;
print(value);
});
},
),
),
)
解决方案
尝试这个 :
items: <String>['A', 'B', 'C', 'D'].map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
推荐阅读
- discord - discord.py-rewrite - 覆盖命令冷却的最佳方法
- css - ion-item 内的 Ionic 4 ion-skeleton 未填充项目空间
- ruby - 为什么某些 ruby 整数不是 Marshal 可转储 to_json
- php - 如何使用 html 表上传 angular 和 laravel 中的多个文件?
- json - Api 响应和 Json laravel 格式
- github - 如何在 GitHub 中创建规则?
- vba - 选择所有没有 ActiveX 按钮的文本
- xamarin.forms - 如何通过 xamarin 表单共享文件(pdf、docx)
- c# - XAML 样式属性没有被继承
- typescript - Iterating a Multidimensional Array in TypeScript