setValue method
void
setValue(})
Merges the provided entries into the form value; optionally removes keys missing from the provided map.
If notifyFields is true (the default), this will call the didChange
method of each field state to update its value and all the side effects,
like validation and notifying listeners.
Only the fields with an updated value will be notified.
Implementation
void setValue(
Map<String, dynamic> value, {
/// When true, notifies the changed form fields of the value changes
bool notifyFields = true,
/// When true, removes keys from the form value that are not present in
/// the provided [value] map.
bool removeMissing = false,
/// When true (and `removeMissing` is true), notifies removed fields.
bool notifyRemovedFields = false,
}) {
if (removeMissing) {
final keysToRemove = _value.keys
.where((key) => !value.containsKey(key))
.toList();
for (final id in keysToRemove) {
removeFieldValue(id, notifyField: notifyRemovedFields);
}
}
for (final entry in value.entries) {
final field = _fields[entry.key];
final oldValue = _value[entry.key];
_value[entry.key] = entry.value;
if (notifyFields && field != null && oldValue != entry.value) {
field.didChange(entry.value);
}
}
}