setRawValue method

  1. @override
void setRawValue(
  1. Object? raw, {
  2. bool notify = true,
})
override

Recursively applies a raw value map to this group and its nested groups.

raw must be a Map<String, dynamic> where each key matches a control name.

  • For nested FormGroup controls, the same raw map is forwarded so the group can pick its own keys.
  • For non-group controls, only the value for the corresponding key is applied.

Notification behavior:

  • Child controls are updated with notify: false to avoid cascading notifications.
  • When notify is true, this FormGroup notifies its listeners after each control update. If you need to notify all controls after a bulk update, prefer calling refreshAll().

Implementation

@override
void setRawValue(Object? raw, {bool notify = true}) {
  if (raw == null) return;

  if (raw is! Map<String, dynamic>) {
    throw ArgumentError(
      'FormGroup.setRawValue espera Map<String, dynamic>. Recebido: ${raw.runtimeType}',
    );
  }

  for (final entry in controls.entries) {
    if(entry.value is FormGroup) {
      final group = entry.value as FormGroup;
      group.setRawValue(raw);
      continue;
    }
    entry.value.setRawValue(raw[entry.key], notify: false);
    if(notify) notifyListeners();
  }
}