FormBuilderSwitch constructor

FormBuilderSwitch({
  1. Key? key,
  2. required String name,
  3. FormFieldValidator<bool>? validator,
  4. bool? initialValue,
  5. InputDecoration decoration = const InputDecoration(),
  6. ValueChanged<bool?>? onChanged,
  7. ValueTransformer<bool?>? valueTransformer,
  8. bool enabled = true,
  9. FormFieldSetter<bool>? onSaved,
  10. AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
  11. VoidCallback? onReset,
  12. FocusNode? focusNode,
  13. String? restorationId,
  14. FormFieldErrorBuilder? errorBuilder,
  15. required Widget title,
  16. Color? activeColor,
  17. Color? activeTrackColor,
  18. Color? inactiveThumbColor,
  19. Color? inactiveTrackColor,
  20. ImageProvider<Object>? activeThumbImage,
  21. ImageProvider<Object>? inactiveThumbImage,
  22. Widget? subtitle,
  23. Widget? secondary,
  24. ListTileControlAffinity controlAffinity = ListTileControlAffinity.trailing,
  25. EdgeInsets contentPadding = EdgeInsets.zero,
  26. bool autofocus = false,
  27. bool selected = false,
})

Creates On/Off switch field

Implementation

FormBuilderSwitch({
  super.key,
  required super.name,
  super.validator,
  super.initialValue,
  super.decoration,
  super.onChanged,
  super.valueTransformer,
  super.enabled,
  super.onSaved,
  super.autovalidateMode = AutovalidateMode.disabled,
  super.onReset,
  super.focusNode,
  super.restorationId,
  super.errorBuilder,
  required this.title,
  this.activeColor,
  this.activeTrackColor,
  this.inactiveThumbColor,
  this.inactiveTrackColor,
  this.activeThumbImage,
  this.inactiveThumbImage,
  this.subtitle,
  this.secondary,
  this.controlAffinity = ListTileControlAffinity.trailing,
  this.contentPadding = EdgeInsets.zero,
  this.autofocus = false,
  this.selected = false,
}) : super(
       builder: (FormFieldState<bool?> field) {
         final state = field as _FormBuilderSwitchState;

         return InputDecorator(
           decoration: state.decoration,
           isFocused: state.effectiveFocusNode.hasFocus,
           child: SwitchListTile(
             focusNode: state.effectiveFocusNode,
             dense: true,
             isThreeLine: false,
             contentPadding: contentPadding,
             title: title,
             value: state.value ?? false,
             onChanged: state.enabled
                 ? (value) {
                     field.didChange(value);
                   }
                 : null,
             activeThumbColor: activeColor,
             activeThumbImage: activeThumbImage,
             activeTrackColor: activeTrackColor,
             inactiveThumbColor: inactiveThumbColor,
             inactiveThumbImage: activeThumbImage,
             inactiveTrackColor: inactiveTrackColor,
             secondary: secondary,
             subtitle: subtitle,
             autofocus: autofocus,
             selected: selected,
             controlAffinity: controlAffinity,
           ),
         );
       },
     );