registerField method
Implementation
void registerField(String name, FormBuilderFieldState field) {
// Each field must have a unique name. Ideally we could simply:
// assert(!_fields.containsKey(name));
// However, Flutter will delay dispose of deactivated fields, so if a
// field is being replaced, the new instance is registered before the old
// one is unregistered. To accommodate that use case, but also provide
// assistance to accidental duplicate names, we check and emit a warning.
final oldField = _fields[name];
assert(() {
if (oldField != null) {
debugPrint('Warning! Replacing duplicate Field for $name'
' -- this is OK to ignore as long as the field was intentionally replaced');
}
return true;
}());
_fields[name] = field;
field.registerTransformer(_transformers);
field.setValue(
oldField?.value ?? (_instantValue[name] ??= field.initialValue),
populateForm: false,
);
}