[英]RadioListTile inside Listview.builder index in flutter
我想在 listview.builder 中设置 RadioListTile 的索引,但我不能这样做,我想在此处获取此索引的值,这是我的代码
int _value=0;
List valueList=[];
ListView.Builder(itemBuilder:(context,index){
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: RadioListTile<int>(
dense: true,
activeColor: colorsCheck(),
contentPadding:
EdgeInsets.symmetric(horizontal: 1.0),
title: Text(
'Present',
style: TextStyle(
color: Colors.white, fontSize: 12.0),
),
value: 1,
groupValue: _value,
onChanged: (value) {
setState(() {
_value=value;
valueList.add(value);
print('radio button value present ${valueList.toList().toString()}');
});
},
),
),
Expanded(
child: RadioListTile<int>(
contentPadding:
EdgeInsets.symmetric(horizontal: 1.0),
dense: true,
activeColor: colorsCheck(),
title: Text(
'Absent',
style: TextStyle(
color: Colors.white, fontSize: 12.0),
),
value: 2,
groupValue: _value,
onChanged: (value) {
setState(() {
_value=value;
valueList.add(value);
print('radio button value absent ${valueList.toList().toString()}');
});
},
),
),
Expanded(
child: RadioListTile<int>(
dense: true,
activeColor: colorsCheck(),
contentPadding:
EdgeInsets.symmetric(horizontal: 1.0),
title: Text(
'Leave',
style: TextStyle(
color: Colors.white, fontSize: 12.0),
),
value: 3,
groupValue:_value,
onChanged: (value) {
setState(() {
_value=value;
valueList.add(value);
print('radio button value leave ${valueList.toList().toString()}');
});
},
),
),
],
),
}
行位于设置了 3 个单选按钮(存在、缺席、离开)的卡片内,但是当我单击它时,所有项目构建器的值都会发生变化。 我只想更改它点击的卡内那个收音机的值。 其他没有。 这是一张图片...
查看图片,其中离开单选按钮仅设置为最高值,但设置为全部。
在 listview.builder 中的 radiotilelist 中设置索引
currentStatus = List<int>.filled(data.length, initialValue);
groupValue: currentStatus[index];
currentStatus[index] = newStatus
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.