radioButtonsBuilder<T> function
List<Widget>
radioButtonsBuilder<T>(
- dynamic items,
- RadioButtonsController controller, {
- double? space,
- MouseCursor? mouseCursor,
- bool? toggleable,
- Color? activeColor,
- WidgetStateProperty<
Color?> ? fillColor, - MaterialTapTargetSize? materialTapTargetSize,
- VisualDensity? visualDensity,
- Color? focusColor,
- Color? hoverColor,
- WidgetStateProperty<
Color?> ? overlayColor, - double? splashRadius,
- FocusNode? focusNode,
- bool? autofocus,
- bool? useCupertinoCheckmarkStyle,
- bool? textFirst,
- TextStyle? style,
- StrutStyle? strutStyle,
- TextAlign? textAlign,
- TextDirection? textDirection,
- Locale? locale,
- bool? softWrap,
- TextOverflow? overflow,
- TextScaler? textScaler,
- int? maxLines,
- String? semanticsLabel,
- TextWidthBasis? textWidthBasis,
- TextHeightBehavior? textHeightBehavior,
- Color? selectionColor,
- int? flex,
- FlexFit? fit,
- Axis? direction,
- MainAxisAlignment? mainAxisAlignment,
- MainAxisSize? mainAxisSize,
- CrossAxisAlignment? crossAxisAlignment,
- VerticalDirection? verticalDirection,
- TextBaseline? textBaseline,
- Clip? clipBehavior,
Returns the 'Radio' widgets
Implementation
List<Widget> radioButtonsBuilder<T>(
// Radio
dynamic items,
RadioButtonsController<dynamic> controller, {
double? space,
MouseCursor? mouseCursor,
bool? toggleable,
Color? activeColor,
WidgetStateProperty<Color?>? fillColor,
MaterialTapTargetSize? materialTapTargetSize,
VisualDensity? visualDensity,
Color? focusColor,
Color? hoverColor,
WidgetStateProperty<Color?>? overlayColor,
double? splashRadius,
FocusNode? focusNode,
bool? autofocus,
bool? useCupertinoCheckmarkStyle,
bool? textFirst,
// Text
TextStyle? style,
StrutStyle? strutStyle,
TextAlign? textAlign,
TextDirection? textDirection,
Locale? locale,
bool? softWrap,
TextOverflow? overflow,
TextScaler? textScaler,
int? maxLines,
String? semanticsLabel,
TextWidthBasis? textWidthBasis,
ui.TextHeightBehavior? textHeightBehavior,
Color? selectionColor,
// Flexible
int? flex,
FlexFit? fit,
// Flex
Axis? direction, // Axis.vertical or Axis.horizontal
MainAxisAlignment? mainAxisAlignment,
MainAxisSize? mainAxisSize,
CrossAxisAlignment? crossAxisAlignment,
VerticalDirection? verticalDirection,
TextBaseline? textBaseline,
Clip? clipBehavior,
}) {
//
Radio<T> buildRadioButton(T value) => Radio<T>.adaptive(
value: value,
groupValue: controller.groupValue,
onChanged: controller.disabled ? null : controller.onChanged,
mouseCursor: mouseCursor,
toggleable: toggleable ?? false,
activeColor: activeColor,
fillColor: fillColor,
focusColor: focusColor,
hoverColor: hoverColor,
overlayColor: overlayColor,
splashRadius: splashRadius,
materialTapTargetSize: materialTapTargetSize,
visualDensity: visualDensity,
focusNode: focusNode,
autofocus: autofocus ?? false,
useCupertinoCheckmarkStyle: useCupertinoCheckmarkStyle ?? false,
);
space ??= 0;
final List<Widget> radioButtons = [];
assert(() {
if (controller.type != T) {
debugPrint(
'############ controller.type == T fails in radiobutton_widget.dart');
}
return true;
}());
if (controller.type == T) {
//
if (items is List<String>) {
//
assert(() {
if (items.runtimeType != T) {
debugPrint(
'############ items.runtimeType == T fails in radiobutton_widget.dart');
}
return true;
}());
if (items.runtimeType == T) {
//
for (final value in items) {
//
var radioItems = [
Flexible(
child: buildRadioButton(value as T),
),
if (space > 0) SizedBox(width: space),
Flexible(
flex: flex ?? 1,
fit: fit ?? FlexFit.loose,
child: Text(
value,
style: style,
strutStyle: strutStyle,
textAlign: textAlign,
textDirection: textDirection,
locale: locale,
softWrap: softWrap,
overflow: overflow,
textScaler: textScaler,
maxLines: maxLines,
semanticsLabel: semanticsLabel,
textWidthBasis: textWidthBasis,
textHeightBehavior: textHeightBehavior,
selectionColor: selectionColor,
),
),
];
if (textFirst ?? false) {
radioItems = radioItems.reversed.toList(growable: false);
}
radioButtons.add(
Flex(
direction: direction ?? Axis.horizontal,
mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.start,
mainAxisSize: mainAxisSize ?? MainAxisSize.max,
crossAxisAlignment:
crossAxisAlignment ?? CrossAxisAlignment.center,
textDirection: textDirection,
verticalDirection: verticalDirection ?? VerticalDirection.down,
textBaseline: textBaseline,
clipBehavior: clipBehavior ?? Clip.none,
children: radioItems),
);
}
}
} else if (items is Map<String, T>) {
//
items.forEach((String key, T value) {
//
var radioItems = [
Flexible(
child: buildRadioButton(value),
),
if (space! > 0) SizedBox(width: space),
Flexible(
flex: flex ?? 1,
fit: fit ?? FlexFit.loose,
child: Text(
key,
style: style,
strutStyle: strutStyle,
textAlign: textAlign,
textDirection: textDirection,
locale: locale,
softWrap: softWrap,
overflow: overflow,
textScaler: textScaler,
maxLines: maxLines,
semanticsLabel: semanticsLabel,
textWidthBasis: textWidthBasis,
textHeightBehavior: textHeightBehavior,
selectionColor: selectionColor,
),
),
];
if (textFirst ?? false) {
radioItems = radioItems.reversed.toList(growable: false);
}
radioButtons.add(
Flex(
direction: direction ?? Axis.horizontal,
mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.start,
mainAxisSize: mainAxisSize ?? MainAxisSize.max,
crossAxisAlignment: crossAxisAlignment ?? CrossAxisAlignment.center,
textDirection: textDirection,
verticalDirection: verticalDirection ?? VerticalDirection.down,
textBaseline: textBaseline,
clipBehavior: clipBehavior ?? Clip.none,
children: radioItems,
),
);
});
}
}
// Nothing to show.
if (radioButtons.isEmpty) {
//
assert(() {
if (radioButtons.isEmpty) {
debugPrint(
'############ items should be a List or a Map in radiobutton_widget.dart');
}
return true;
}());
radioButtons.add(const SizedBox.shrink());
}
return radioButtons;
}