ShadSwitchFormField constructor

ShadSwitchFormField({
  1. String? id,
  2. Key? key,
  3. FormFieldSetter<bool>? onSaved,
  4. String? forceErrorText,
  5. Widget? label,
  6. Widget error(
    1. String error
    )?,
  7. Widget? description,
  8. void onChanged(
    1. bool
    )?,
  9. @Deprecated('Use toValueTransformer instead') ToValueTransformer<bool?>? valueTransformer,
  10. ToValueTransformer<bool?>? toValueTransformer,
  11. FromValueTransformer<bool?>? fromValueTransformer,
  12. VoidCallback? onReset,
  13. bool enabled = true,
  14. AutovalidateMode? autovalidateMode,
  15. String? restorationId,
  16. required bool initialValue,
  17. ShadDecoration? decoration,
  18. FocusNode? focusNode,
  19. String? validator(
    1. bool
    )?,
  20. Color? thumbColor,
  21. Color? uncheckedTrackColor,
  22. Color? checkedTrackColor,
  23. double? width,
  24. double? margin,
  25. Duration? duration,
  26. Widget? inputLabel,
  27. Widget? inputSublabel,
  28. EdgeInsetsGeometry? padding,
  29. 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,
         );
       },
     );