[英]Populate DropdownButton with sqflite in Flutter, when selecting value(OnChange) returns error
[英]Flutter DropdownButton returns error for onChange event
我正在編寫一個項目並想添加一個 DropDownButton 但是一旦我添加 onCnange 事件它總是返回錯誤。 下拉菜單總是返回錯誤。 我不知道它有什么問題。
@override
Widget build(BuildContext context) {
return Material( child: Column( children: [
DropdownButton(items: [], value: dropdownValue, onChanged: (String value) {
setState(() {
dropdownValue = value;
});
},)
], ), );
}
錯誤信息
The argument type 'void Function(String)' can't be assigned to the parameter type 'void Function(Object?)?'.
function 和值可能為空,因此要么從回調中刪除String
類型,要么使用可空類型。
解決方案 1
DropdownButton<String>(
items: [],
value: dropdownValue,
onChanged: (value) {
setState(() {
dropdownValue = value;
});
},
)
解決方案 2
DropdownButton<String>(
items: [],
value: dropdownValue,
onChanged: (String? value) {
setState(() {
dropdownValue = value;
});
},
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.