FormBuilderSwitch constructor
FormBuilderSwitch({
- Key? key,
- required String name,
- FormFieldValidator<
bool> ? validator, - bool? initialValue,
- InputDecoration decoration = const InputDecoration(),
- ValueChanged<
bool?> ? onChanged, - ValueTransformer<
bool?> ? valueTransformer, - bool enabled = true,
- FormFieldSetter<
bool> ? onSaved, - AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
- VoidCallback? onReset,
- FocusNode? focusNode,
- required Widget title,
- Color? activeColor,
- Color? activeTrackColor,
- Color? inactiveThumbColor,
- Color? inactiveTrackColor,
- ImageProvider<
Object> ? activeThumbImage, - ImageProvider<
Object> ? inactiveThumbImage, - Widget? subtitle,
- Widget? secondary,
- ListTileControlAffinity controlAffinity = ListTileControlAffinity.trailing,
- EdgeInsets contentPadding = EdgeInsets.zero,
- bool autofocus = false,
- bool selected = false,
Creates On/Off switch field
Implementation
FormBuilderSwitch({
Key? key,
//From Super
required String name,
FormFieldValidator<bool>? validator,
bool? initialValue,
InputDecoration decoration = const InputDecoration(),
ValueChanged<bool?>? onChanged,
ValueTransformer<bool?>? valueTransformer,
bool enabled = true,
FormFieldSetter<bool>? onSaved,
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
VoidCallback? onReset,
FocusNode? focusNode,
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(
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<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
? (val) {
state.requestFocus();
field.didChange(val);
}
: null,
activeColor: activeColor,
activeThumbImage: activeThumbImage,
activeTrackColor: activeTrackColor,
inactiveThumbColor: inactiveThumbColor,
inactiveThumbImage: activeThumbImage,
inactiveTrackColor: inactiveTrackColor,
secondary: secondary,
subtitle: subtitle,
autofocus: autofocus,
selected: selected,
controlAffinity: controlAffinity,
),
);
},
);