Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 views
in Technique[技术] by (71.8m points)

RadioListTile inside Listview.builder index in flutter

I want to set the index of RadioListTile inside the listview.builder but i can't do that how to do it which I want to get the value of this index here is my code

         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()}');
                                  });
                                },
                              ),
                            ),
                          ],
                        ),

             }

Row is inside card where 3 radio button is set (present, absent, leave) but when I click it changes all item builder value. I just want to change the value of that radio inside the card which it clicks. other not. here is an image ...

enter image description here

look inside the picture where the leave radio button is set only top value but it set all.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

set index in radiotilelist inside listview.builder

   currentStatus = List<int>.filled(data.length, initialValue);
    groupValue: currentStatus[index];
   currentStatus[index] = newStatus

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...