ShadSwitchFormField constructor
ShadSwitchFormField({
- String? id,
- Key? key,
- FormFieldSetter<
bool> ? onSaved, - String? forceErrorText,
- Widget? label,
- Widget error(
- String error
- Widget? description,
- void onChanged()?,
- @Deprecated('Use toValueTransformer instead') ToValueTransformer<
bool?> ? valueTransformer, - ToValueTransformer<
bool?> ? toValueTransformer, - FromValueTransformer<
bool?> ? fromValueTransformer, - VoidCallback? onReset,
- bool enabled = true,
- AutovalidateMode? autovalidateMode,
- String? restorationId,
- required bool initialValue,
- ShadDecoration? decoration,
- FocusNode? focusNode,
- String? validator()?,
- Color? thumbColor,
- Color? uncheckedTrackColor,
- Color? checkedTrackColor,
- double? width,
- double? margin,
- Duration? duration,
- Widget? inputLabel,
- Widget? inputSublabel,
- EdgeInsetsGeometry? padding,
- TextDirection? direction,
Implementation
ShadSwitchFormField({
super.id,
super.key,
super.onSaved,
super.forceErrorText,
super.label,
super.error,
super.description,
void Function(bool)? onChanged,
@Deprecated('Use toValueTransformer instead') super.valueTransformer,
super.toValueTransformer,
super.fromValueTransformer,
super.onReset,
super.enabled,
super.autovalidateMode,
super.restorationId,
/// {@macro ShadFormBuilderField.initialValue}
required bool initialValue,
/// {@macro ShadSwitch.decoration}
ShadDecoration? decoration,
super.focusNode,
/// {@macro ShadFormBuilderField.validator}
String? Function(bool)? validator,
/// {@macro ShadSwitch.thumbColor}
Color? thumbColor,
/// {@macro ShadSwitch.uncheckedTrackColor}
Color? uncheckedTrackColor,
/// {@macro ShadSwitch.checkedTrackColor}
Color? checkedTrackColor,
/// {@macro ShadSwitch.width}
double? width,
/// {@macro ShadSwitch.margin}
double? margin,
/// {@macro ShadSwitch.duration}
Duration? duration,
/// {@macro ShadSwitch.inputLabel}
Widget? inputLabel,
/// {@macro ShadSwitch.inputSublabel}
Widget? inputSublabel,
/// {@macro ShadSwitch.padding}
EdgeInsetsGeometry? padding,
/// {@macro ShadSwitch.direction}
TextDirection? direction,
}) : super(
initialValue: initialValue,
onChanged: (!enabled || onChanged == null)
? null
: (v) => onChanged(v ?? false),
validator: validator == null
? null
: (v) {
return validator(v ?? false);
},
decorationBuilder: (context) =>
(ShadTheme.of(context).switchTheme.decoration ??
const ShadDecoration())
.merge(decoration),
builder: (state) {
state as ShadFormBuilderSwitchState;
return ShadSwitch(
value: state.value!,
onChanged: state.didChange,
enabled: state.enabled,
focusNode: state.focusNode,
decoration: state.decoration,
duration: duration,
label: inputLabel,
sublabel: inputSublabel,
padding: padding,
direction: direction,
width: width,
margin: margin,
thumbColor: thumbColor,
uncheckedTrackColor: uncheckedTrackColor,
checkedTrackColor: checkedTrackColor,
);
},
);