FormBuilderSegmentedControl<T extends Object> constructor
FormBuilderSegmentedControl<T extends Object> ({
- Key? key,
- required String name,
- FormFieldValidator<
T> ? validator, - T? initialValue,
- InputDecoration decoration = const InputDecoration(),
- ValueChanged<
T?> ? onChanged, - ValueTransformer<
T?> ? valueTransformer, - bool enabled = true,
- FormFieldSetter<
T> ? onSaved, - AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
- VoidCallback? onReset,
- FocusNode? focusNode,
- required List<
FormBuilderFieldOption< options,T> > - Color? borderColor,
- Color? selectedColor,
- Color? pressedColor,
- EdgeInsetsGeometry? padding,
- Color? unselectedColor,
Creates field for selection of a value from the CupertinoSegmentedControl
Implementation
FormBuilderSegmentedControl({
Key? key,
//From Super
required String name,
FormFieldValidator<T>? validator,
T? initialValue,
InputDecoration decoration = const InputDecoration(),
ValueChanged<T?>? onChanged,
ValueTransformer<T?>? valueTransformer,
bool enabled = true,
FormFieldSetter<T>? onSaved,
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
VoidCallback? onReset,
FocusNode? focusNode,
required this.options,
this.borderColor,
this.selectedColor,
this.pressedColor,
this.padding,
this.unselectedColor,
}) : super(
key: key,
initialValue: initialValue,
name: name,
validator: validator,
valueTransformer: valueTransformer,
onChanged: onChanged,
autovalidateMode: autovalidateMode,
onSaved: onSaved,
enabled: enabled,
onReset: onReset,
decoration: decoration,
focusNode: focusNode,
builder: (FormFieldState<T?> field) {
final state = field as _FormBuilderSegmentedControlState<T>;
final theme = Theme.of(state.context);
return InputDecorator(
decoration: state.decoration,
child: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: CupertinoSegmentedControl<T>(
borderColor: state.enabled
? borderColor ?? theme.primaryColor
: theme.disabledColor,
selectedColor: state.enabled
? selectedColor ?? theme.primaryColor
: theme.disabledColor,
pressedColor: state.enabled
? pressedColor ?? theme.primaryColor
: theme.disabledColor,
groupValue: state.value,
children: <T, Widget>{
for (final option in options)
option.value: Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: option,
),
},
padding: padding,
unselectedColor: unselectedColor,
onValueChanged: (value) {
state.requestFocus();
if (state.enabled) {
field.didChange(value);
} else {
field.reset();
}
},
),
),
);
},
);