我使用的是顫振 2.8.1,所以我的想法是我使用有狀態的 Radio 小部件,然后當我嘗試用新值 / onChanged:(value) 更改 Radio 小部件的 groupValue 時,它??會告訴這個
該值有紅色下劃線
Object? value
A value of type 'Object?' can't be assigned to a variable of type 'int'.
Try changing the type of the variable, or casting the right-hand type to 'int'.
代碼
int radioValue = 0;
Radio(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
value: index,
groupValue: radioValue,
onChanged: (value) {
print(e['value']);
setState(() {
radioValue = value;
});
},
),

uj5u.com熱心網友回復:
Radio<int>(
value: radioValue,
groupValue: 2,
onChanged: (v) {
setState(() {
radioValue = v!;
});
},
)
uj5u.com熱心網友回復:
將 Radio 更改為Radio<int>并將值更改為value!
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/430830.html
下一篇:我可以使用if更改小部件嗎?
