当我使用医院作为下拉菜单中onChangeEvent的参数时,Flutter 会产生以下错误:
无法将参数类型"void Function(医院)"分配给
医院
class 医院 {
final int Id;
final String Name;
final int BranchId;
const 医院(
{required this.Id, required this.Name, required this.BranchId});
factory 医院.fromJson(Map<String, dynamic> json) {
return 医院(
Id: json['id'], Name: json['name'], BranchId: json['branchId']);
}
}
下拉代码
DropdownButton(
style: const TextStyle(
color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (医院 newValue) {
setState(() {
hospitalDropdownValue = newValue.id;
branchDropdownValue = newValue.BranchId;
});
},
items: _hospitals.map<DropdownMenuItem<医院>>((医院 item) {
return DropdownMenuItem<医院>(
child: Text(item.Name),
value: item,
);
}).toList(),
value: hospitalDropdownValue,
hint: const Text("医院 Name"),
),