@@ -173,7 +173,7 @@ class GroupedRadio<T> extends StatefulWidget {
173
173
final ControlAffinity controlAffinity;
174
174
175
175
const GroupedRadio ({
176
- Key ? key,
176
+ super . key,
177
177
required this .options,
178
178
required this .orientation,
179
179
required this .onChanged,
@@ -193,7 +193,7 @@ class GroupedRadio<T> extends StatefulWidget {
193
193
this .wrapVerticalDirection = VerticalDirection .down,
194
194
this .separator,
195
195
this .controlAffinity = ControlAffinity .leading,
196
- }) : super (key : key) ;
196
+ });
197
197
198
198
@override
199
199
State <GroupedRadio <T ?>> createState () => _GroupedRadioState <T >();
@@ -203,46 +203,43 @@ class _GroupedRadioState<T> extends State<GroupedRadio<T?>> {
203
203
@override
204
204
Widget build (BuildContext context) {
205
205
final widgetList = < Widget > [];
206
- for (var i = 0 ; i < widget.options.length; i++ ) {
207
- widgetList.add (item (i));
206
+ for (int i = 0 ; i < widget.options.length; i++ ) {
207
+ widgetList.add (_buildRadioButton (i));
208
208
}
209
- Widget finalWidget;
210
- if (widget.orientation == OptionsOrientation .vertical) {
211
- finalWidget = SingleChildScrollView (
212
- scrollDirection: Axis .vertical,
213
- child: Column (
214
- crossAxisAlignment: CrossAxisAlignment .start,
215
- children: widgetList,
216
- ),
217
- );
218
- } else if (widget.orientation == OptionsOrientation .horizontal) {
219
- finalWidget = SingleChildScrollView (
220
- scrollDirection: Axis .horizontal,
221
- child: Row (
222
- children: widgetList.map ((item) {
223
- return Column (children: < Widget > [item]);
224
- }).toList (),
225
- ),
226
- );
227
- } else {
228
- finalWidget = SingleChildScrollView (
229
- child: Wrap (
230
- spacing: widget.wrapSpacing,
231
- runSpacing: widget.wrapRunSpacing,
232
- textDirection: widget.wrapTextDirection,
233
- crossAxisAlignment: widget.wrapCrossAxisAlignment,
234
- verticalDirection: widget.wrapVerticalDirection,
235
- alignment: widget.wrapAlignment,
236
- direction: Axis .horizontal,
237
- runAlignment: widget.wrapRunAlignment,
238
- children: widgetList,
239
- ),
240
- );
209
+
210
+ switch (widget.orientation) {
211
+ case OptionsOrientation .vertical:
212
+ return SingleChildScrollView (
213
+ scrollDirection: Axis .vertical,
214
+ child: Column (
215
+ crossAxisAlignment: CrossAxisAlignment .start,
216
+ children: widgetList,
217
+ ),
218
+ );
219
+ case OptionsOrientation .horizontal:
220
+ return SingleChildScrollView (
221
+ scrollDirection: Axis .horizontal,
222
+ child: Row (children: widgetList),
223
+ );
224
+ case OptionsOrientation .wrap:
225
+ default :
226
+ return SingleChildScrollView (
227
+ child: Wrap (
228
+ spacing: widget.wrapSpacing,
229
+ runSpacing: widget.wrapRunSpacing,
230
+ textDirection: widget.wrapTextDirection,
231
+ crossAxisAlignment: widget.wrapCrossAxisAlignment,
232
+ verticalDirection: widget.wrapVerticalDirection,
233
+ alignment: widget.wrapAlignment,
234
+ direction: Axis .horizontal,
235
+ runAlignment: widget.wrapRunAlignment,
236
+ children: widgetList,
237
+ ),
238
+ );
241
239
}
242
- return finalWidget;
243
240
}
244
241
245
- Widget item (int index) {
242
+ Widget _buildRadioButton (int index) {
246
243
final option = widget.options[index];
247
244
final optionValue = option.value;
248
245
final isOptionDisabled = true == widget.disabled? .contains (optionValue);
@@ -266,16 +263,28 @@ class _GroupedRadioState<T> extends State<GroupedRadio<T?>> {
266
263
: () {
267
264
widget.onChanged (optionValue);
268
265
},
269
- child: widget.options[index] ,
266
+ child: option ,
270
267
);
271
268
272
- return Row (
269
+ return Column (
273
270
mainAxisSize: MainAxisSize .min,
271
+ crossAxisAlignment: CrossAxisAlignment .start,
274
272
children: [
275
- if (widget.controlAffinity == ControlAffinity .leading) control,
276
- Flexible (child: label),
277
- if (widget.controlAffinity == ControlAffinity .trailing) control,
278
- if (widget.separator != null && index != widget.options.length - 1 )
273
+ Row (
274
+ mainAxisSize: MainAxisSize .min,
275
+ children: [
276
+ if (widget.controlAffinity == ControlAffinity .leading) control,
277
+ Flexible (child: label),
278
+ if (widget.controlAffinity == ControlAffinity .trailing) control,
279
+ if (widget.orientation != OptionsOrientation .vertical &&
280
+ widget.separator != null &&
281
+ index != widget.options.length - 1 )
282
+ widget.separator! ,
283
+ ],
284
+ ),
285
+ if (widget.orientation == OptionsOrientation .vertical &&
286
+ widget.separator != null &&
287
+ index != widget.options.length - 1 )
279
288
widget.separator! ,
280
289
],
281
290
);
0 commit comments