【发布时间】:2022-02-15 20:11:25
【问题描述】:
我有一个 API,其中包含一个值数组列表,可以成功地将值传递给我的单选按钮。当我选择每个选择值解析但我无法取消选择选择单选按钮。下面是我的颤振代码:
ListView.builder( shrinkWrap:true,
physics:const NeverScrollableScrollPhysics(),
itemCount:dataOptions == null? 0: dataOptions.length,
itemBuilder:(BuildContext context,int index) {
return Container(
padding:
const EdgeInsets
.only(
bottom:
0.0),
child: Card(
elevation: 0,
child:
ListTile(
title: Text(
dataOptions[index]['option_title']),
leading:
Radio(
value: dataOptions[index]["option_price"],
//below will be the default value.
groupValue: dataOptions[index]["option_id"],
onChanged: (value) {
setState(
() {
dataOptions[index]["option_id"] = value;
debugPrint("radioSel:$value");
});
},
activeColor: Colors.green,
),
trailing:
Text(dataOptions[index]['option_price'].toString(), style:TextStyle(fontFamily: 'Montserrat',
color: colorPink, fontWeight: FontWeight.bold,
fontSize: 15,
),
),
)));
})
【问题讨论】:
-
请解释您要达到的目标。您希望能够一次选择多个单选按钮并取消选择它们吗?还是您想始终一次选择一个?
标签: flutter radio-button radio-group radiobuttonlist