如何創建行內函式來修復此錯誤:
The argument type 'void Function()' can't be assigned to the parameter type 'void Function.
考慮以下代碼:
Switch(value: _showChart, onChanged: () { //this generates the error
setState(() {
_showChart = value;
});
},)
如果我將它提取到一個函式,它看起來像這樣,但我不想這樣做:
VoidCallback? onSwitch(val){
setState(() {
_showChart = val;
});
}
有沒有辦法做到行內?
uj5u.com熱心網友回復:
onChanged: 包含一個值引數。
你錯過了一個錯字,value引數。這將是,
Switch(
value: true,
onChanged: (value) {
setState(() {
_showChart = value;
});
},
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/374327.html
