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. required Widget title,
  15. Color? activeColor,
  16. Color? activeTrackColor,
  17. Color? inactiveThumbColor,
  18. Color? inactiveTrackColor,
  19. ImageProvider<Object>? activeThumbImage,
  20. ImageProvider<Object>? inactiveThumbImage,
  21. Widget? subtitle,
  22. Widget? secondary,
  23. ListTileControlAffinity controlAffinity = ListTileControlAffinity.trailing,
  24. EdgeInsets contentPadding = EdgeInsets.zero,
  25. bool autofocus = false,
  26. 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,
  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,
            child: SwitchListTile(
              dense: true,
              isThreeLine: false,
              contentPadding: contentPadding,
              title: title,
              value: state.value ?? false,
              onChanged: state.enabled
                  ? (value) {
                      field.didChange(value);
                    }
                  : null,
              activeColor: activeColor,
              activeThumbImage: activeThumbImage,
              activeTrackColor: activeTrackColor,
              inactiveThumbColor: inactiveThumbColor,
              inactiveThumbImage: activeThumbImage,
              inactiveTrackColor: inactiveTrackColor,
              secondary: secondary,
              subtitle: subtitle,
              autofocus: autofocus,
              selected: selected,
              controlAffinity: controlAffinity,
            ),
          );
        },
      );