@@ -7,7 +7,7 @@ class YYRadioListTile extends StatefulWidget {
77  YYRadioListTile ({
88    Key  key,
99    this .items,
10-     this .intialValue  =   0 ,
10+     this .intialValue,
1111    this .activeColor,
1212    this .onChanged,
1313  })  :  assert (items !=  null ),
@@ -25,32 +25,38 @@ class YYRadioListTile extends StatefulWidget {
2525}
2626
2727class  YYRadioListTileState  extends  State <YYRadioListTile > {
28-   var  groupId =  0 ;
29-   var  selectedItem =  - 1 ;
28+   var  groupId =  - 1 ;
29+ 
30+   void  intialSelectedItem () {
31+     //intialValue: 
32+     //The button initializes the position. 
33+     //If it is not filled, it is not selected. 
34+     if  (groupId ==  - 1 ) {
35+       groupId =  widget.intialValue ??  - 1 ;
36+     }
37+   }
3038
3139  @override 
3240  Widget  build (BuildContext  context) {
33-     if  (selectedItem ==  - 1 ) {
34-       selectedItem =  widget.intialValue !=  null  ?  widget.intialValue :  0 ;
35-     }
41+     intialSelectedItem ();
42+ 
3643    return  ListView .builder (
3744      padding:  EdgeInsets .all (0.0 ),
3845      shrinkWrap:  true ,
3946      itemCount:  widget.items.length,
4047      itemBuilder:  (BuildContext  context, int  index) {
41-         var  radioItem =  widget.items[index];
4248        return  Material (
4349          color:  Colors .white,
4450          child:  RadioListTile (
45-             title:  Text (radioItem .text),
46-             value:  radioItem.value  ==   null   ?   index  :  radioItem.value ,
47-             groupValue:  selectedItem ,
51+             title:  Text (widget.items[index] .text),
52+             value:  index,
53+             groupValue:  groupId ,
4854            activeColor:  widget.activeColor,
4955            onChanged:  (int  value) {
5056              setState (() {
51-                 selectedItem =  value;
57+                 widget.onChanged (value);
58+                 groupId =  value;
5259              });
53-               widget.onChanged (value);
5460            },
5561          ),
5662        );
0 commit comments