我有一份品种清单[Chocolate, Strawberry, Vanilla]
此列表可根据订购的菜单项(即[BBQ, Medium, Peri-Peri, Lemon & Herb]
(进行更改
我当前正确显示按钮但不起作用的代码是:
ListView.builder(
shrinkWrap: true,
itemCount: varietyList.length,
itemBuilder: ((context, index) {
return GFRadioListTile(
titleText: varietyList[index],
size: 25,
activeBorderColor: Colors.black,
focusColor: Colors.black,
type: GFRadioType.basic,
value: 0,
groupValue: 1,
onChanged: (value) {},
inactiveIcon: null,
);
})),
其中``int number=20''。这个变量和金额是基于另一篇帖子,代码如下:
ListView.builder(
shrinkWrap: true,
itemCount: varietyList.length,
itemBuilder: ((context, index) {
return RadioListTile(
value: index,
groupValue: number,
onChanged: (ind) => setState(() => number = ind),
);
})),
但上面写着";"Object?"类型的值无法将其分配给"int"类型的变量">
如何使收音机按钮正常工作?
修复"对象不能是int";问题是我必须为ind
对象添加as int
。
GFRadioListTile(
padding: const EdgeInsets.all(13),
color: Colors.white,
radioColor: Color.fromARGB(255, 138, 5, 5),
title: Text(
varietyList[index],
style: const TextStyle(
fontSize: 25, color: Colors.black),
),
size: 28,
activeBorderColor: Colors.black,
focusColor: Colors.black,
type: GFRadioType.basic,
value: index,
groupValue: number,
onChanged: (ind) =>
setState(() => number = ind! as int),
inactiveIcon: null,
);