setValue method
Sets the value for a given form configuration.
If the form configuration type is 'multicheckbox', it handles adding or removing the value from the list. Otherwise, it sets the value directly.
Notifies listeners after updating the value.
Implementation
void setValue(FormConfig config, dynamic value) {
if (formValues.any((form) => form.id == config.id)) {
formValues.removeWhere((form) => form.id == config.id);
}
if (config.type == 'multicheckbox') {
config.value ??= <String>[];
final values = config.value as List<String>;
if (values.any((existingValue) => existingValue == value)) {
values.remove(value);
} else {
values.add(value);
}
} else {
config.value = value;
}
formValues.add(
FormValue(
id: config.id,
formKey: config.formKey,
label: config.label,
value: config.value,
),
);
notifyListeners();
}