CheckboxSuperFormField<T>.listTile constructor
CheckboxSuperFormField<T>.listTile ({
- Key? key,
- required String name,
- required List<
CheckboxOption< options,T> > - List<
SuperFormFieldRule> ? rules, - Color? activeColor,
- Color? checkColor,
- Color? tileColor,
- Widget subtitle(
- CheckboxOption<
T> state
- CheckboxOption<
- bool isThreeLine = false,
- bool? dense,
- Widget? secondary,
- bool selected(
- CheckboxOption<
T> option
- CheckboxOption<
- ListTileControlAffinity controlAffinity = ListTileControlAffinity.platform,
- bool autofocus = false,
- EdgeInsetsGeometry? contentPadding,
- ShapeBorder? shape,
- Color? selectedTileColor,
- void onChanged(
- T value,
- bool checked
- bool? enabled,
Creates a Column of connected CheckboxListTiles which represent the options.
Check CheckboxListTile documentation for arguments documentation.
Diffences between CheckboxListTile and this builder are:
- No tristate available
subtitle
is a function so developers can customize it per optionselected
is a function so developers can customize it per option
Implementation
CheckboxSuperFormField.listTile({
Key? key,
required String name,
required this.options,
List<SuperFormFieldRule>? rules,
Color? activeColor,
Color? checkColor,
Color? tileColor,
Widget Function(CheckboxOption<T> state)? subtitle,
bool isThreeLine = false,
bool? dense,
Widget? secondary,
bool Function(CheckboxOption<T> option)? selected,
ListTileControlAffinity controlAffinity = ListTileControlAffinity.platform,
bool autofocus = false,
EdgeInsetsGeometry? contentPadding,
ShapeBorder? shape,
Color? selectedTileColor,
void Function(T value, bool checked)? onChanged,
this.enabled,
}) : super(
key: key,
name: name,
rules: rules ?? [],
builder: (context, fieldState, formState) {
final List<T> currentValue =
List.from(fieldState.data?.value as List? ?? []);
void effectiveOnChanged(T value, bool checked) {
List<T> newValue = currentValue;
if (checked) {
if (!currentValue.contains(value)) {
newValue = <T>[...currentValue, value];
}
} else {
newValue = currentValue
.where((element) => element != value)
.toList(growable: false);
}
SuperFormFieldData newData = fieldState.data!.copyWithValue(
value: newValue,
touched: true,
);
// If the field was tried to be submitted it should be now revalidated every change
if (formState.validationMode == ValidationMode.onChange ||
newData.submitted) {
newData = newData.validate(rules ?? []);
}
formState.updateFieldData(newData);
if (onChanged != null) {
onChanged(value, checked);
}
}
final effectiveEnabled = enabled ?? formState.enabled;
return listTileCheckboxBuilder(
context,
CheckboxState<T>(
options,
currentValue,
effectiveEnabled ? effectiveOnChanged : null,
fieldState.focusNode,
),
activeColor: activeColor,
checkColor: checkColor,
tileColor: tileColor,
subtitle: subtitle,
isThreeLine: isThreeLine,
dense: dense,
secondary: secondary,
selected: selected,
controlAffinity: controlAffinity,
autofocus: autofocus,
contentPadding: contentPadding,
shape: shape,
selectedTileColor: selectedTileColor,
);
},
);