Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...