@@ -15,31 +15,21 @@ class LinkedLabelRadio extends StatelessWidget {
15
15
const LinkedLabelRadio ({
16
16
required this .label,
17
17
required this .padding,
18
- required this .groupValue,
19
18
required this .value,
20
- required this .onChanged,
21
19
super .key,
22
20
});
23
21
24
22
final String label;
25
23
final EdgeInsets padding;
26
- final bool groupValue;
27
24
final bool value;
28
- final ValueChanged <bool ?> onChanged;
29
25
30
26
@override
31
27
Widget build (BuildContext context) {
32
28
return Padding (
33
29
padding: padding,
34
30
child: Row (
35
31
children: < Widget > [
36
- Radio <bool >(
37
- groupValue: groupValue,
38
- value: value,
39
- onChanged: (bool ? newValue) {
40
- onChanged (newValue);
41
- },
42
- ),
32
+ Radio <bool >(value: value),
43
33
RichText (
44
34
text: TextSpan (
45
35
text: label,
@@ -63,37 +53,23 @@ class LabeledRadio extends StatelessWidget {
63
53
const LabeledRadio ({
64
54
required this .label,
65
55
required this .padding,
66
- required this .groupValue,
67
56
required this .value,
68
- required this .onChanged,
69
57
super .key,
70
58
});
71
59
72
60
final String label;
73
61
final EdgeInsets padding;
74
- final bool groupValue;
75
62
final bool value;
76
- final ValueChanged <bool ?> onChanged;
77
63
78
64
@override
79
65
Widget build (BuildContext context) {
80
66
return InkWell (
81
- onTap: () {
82
- if (value != groupValue) {
83
- onChanged (value);
84
- }
85
- },
67
+ onTap: () {},
86
68
child: Padding (
87
69
padding: padding,
88
70
child: Row (
89
71
children: < Widget > [
90
- Radio <bool >(
91
- groupValue: groupValue,
92
- value: value,
93
- onChanged: (bool ? newValue) {
94
- onChanged (newValue);
95
- },
96
- ),
72
+ Radio <bool >(value: value),
97
73
Text (label),
98
74
],
99
75
),
@@ -127,29 +103,25 @@ class _RadioListTileDiagramState extends State<RadioListTileDiagram> {
127
103
alignment: FractionalOffset .center,
128
104
padding: const EdgeInsets .all (5.0 ),
129
105
color: Colors .white,
130
- child: Column (
131
- children: < Widget > [
132
- RadioListTile <SingingCharacter >(
133
- title: const Text ('Lafayette' ),
134
- value: SingingCharacter .lafayette,
135
- groupValue: _character,
136
- onChanged: (SingingCharacter ? value) {
137
- setState (() {
138
- _character = value;
139
- });
140
- },
141
- ),
142
- RadioListTile <SingingCharacter >(
143
- title: const Text ('Thomas Jefferson' ),
144
- value: SingingCharacter .jefferson,
145
- groupValue: _character,
146
- onChanged: (SingingCharacter ? value) {
147
- setState (() {
148
- _character = value;
149
- });
150
- },
151
- ),
152
- ],
106
+ child: RadioGroup <SingingCharacter ?>(
107
+ groupValue: _character,
108
+ onChanged: (SingingCharacter ? value) {
109
+ setState (() {
110
+ _character = value;
111
+ });
112
+ },
113
+ child: const Column (
114
+ children: < Widget > [
115
+ RadioListTile <SingingCharacter >(
116
+ title: Text ('Lafayette' ),
117
+ value: SingingCharacter .lafayette,
118
+ ),
119
+ RadioListTile <SingingCharacter >(
120
+ title: Text ('Thomas Jefferson' ),
121
+ value: SingingCharacter .jefferson,
122
+ ),
123
+ ],
124
+ ),
153
125
),
154
126
),
155
127
);
@@ -161,31 +133,27 @@ class _RadioListTileDiagramState extends State<RadioListTileDiagram> {
161
133
alignment: FractionalOffset .center,
162
134
padding: const EdgeInsets .all (5.0 ),
163
135
color: Colors .white,
164
- child: Column (
165
- children: < Widget > [
166
- LinkedLabelRadio (
167
- label: 'First tappable label text' ,
168
- padding: const EdgeInsets .symmetric (horizontal: 5.0 ),
169
- value: true ,
170
- groupValue: _isRadioSelected,
171
- onChanged: (bool ? newValue) {
172
- setState (() {
173
- _isRadioSelected = newValue! ;
174
- });
175
- },
176
- ),
177
- LinkedLabelRadio (
178
- label: 'Second tappable label text' ,
179
- padding: const EdgeInsets .symmetric (horizontal: 5.0 ),
180
- value: false ,
181
- groupValue: _isRadioSelected,
182
- onChanged: (bool ? newValue) {
183
- setState (() {
184
- _isRadioSelected = newValue! ;
185
- });
186
- },
187
- ),
188
- ],
136
+ child: RadioGroup <bool >(
137
+ groupValue: _isRadioSelected,
138
+ onChanged: (bool ? newValue) {
139
+ setState (() {
140
+ _isRadioSelected = newValue! ;
141
+ });
142
+ },
143
+ child: const Column (
144
+ children: < Widget > [
145
+ LinkedLabelRadio (
146
+ label: 'First tappable label text' ,
147
+ padding: EdgeInsets .symmetric (horizontal: 5.0 ),
148
+ value: true ,
149
+ ),
150
+ LinkedLabelRadio (
151
+ label: 'Second tappable label text' ,
152
+ padding: EdgeInsets .symmetric (horizontal: 5.0 ),
153
+ value: false ,
154
+ ),
155
+ ],
156
+ ),
189
157
),
190
158
),
191
159
);
@@ -197,31 +165,27 @@ class _RadioListTileDiagramState extends State<RadioListTileDiagram> {
197
165
alignment: FractionalOffset .center,
198
166
padding: const EdgeInsets .all (5.0 ),
199
167
color: Colors .white,
200
- child: Column (
201
- children: < Widget > [
202
- LabeledRadio (
203
- label: 'This is the first label text' ,
204
- padding: const EdgeInsets .symmetric (horizontal: 5.0 ),
205
- value: true ,
206
- groupValue: _isRadioSelected,
207
- onChanged: (bool ? newValue) {
208
- setState (() {
209
- _isRadioSelected = newValue! ;
210
- });
211
- },
212
- ),
213
- LabeledRadio (
214
- label: 'This is the second label text' ,
215
- padding: const EdgeInsets .symmetric (horizontal: 5.0 ),
216
- value: false ,
217
- groupValue: _isRadioSelected,
218
- onChanged: (bool ? newValue) {
219
- setState (() {
220
- _isRadioSelected = newValue! ;
221
- });
222
- },
223
- ),
224
- ],
168
+ child: RadioGroup <bool ?>(
169
+ groupValue: _isRadioSelected,
170
+ onChanged: (bool ? newValue) {
171
+ setState (() {
172
+ _isRadioSelected = newValue! ;
173
+ });
174
+ },
175
+ child: const Column (
176
+ children: < Widget > [
177
+ LabeledRadio (
178
+ label: 'This is the first label text' ,
179
+ padding: EdgeInsets .symmetric (horizontal: 5.0 ),
180
+ value: true ,
181
+ ),
182
+ LabeledRadio (
183
+ label: 'This is the second label text' ,
184
+ padding: EdgeInsets .symmetric (horizontal: 5.0 ),
185
+ value: false ,
186
+ ),
187
+ ],
188
+ ),
225
189
),
226
190
),
227
191
);
0 commit comments