toggleCheckbox<T> method

void toggleCheckbox<T>(
  1. String fieldName, {
  2. required T value,
  3. bool? selected,
})

Toggles the value of a specific checkbox within a checkbox group.

Updates the set of selected values for the checkbox group field specified by fieldName to either include or exclude the given value based on the selected parameter.

fieldName The name of the field associated with the checkbox group. value The value of the specific checkbox to toggle. selected A boolean indicating whether the checkbox is selected (true) or not (false). If null, the checkbox will be treated as not selected.

This method automatically updates the state of the checkbox group field.

Implementation

void toggleCheckbox<T>(String fieldName, {required T value, bool? selected}) {
  final currentValues = state.checkboxValues<T>(fieldName);
  if (selected ?? false) {
    currentValues.add(value);
  } else {
    currentValues.remove(value);
  }
  updateCheckboxGroup<T>(fieldName, currentValues);
}