setValue method

  1. @override
void setValue(
  1. Map<String, dynamic> val, {
  2. bool notify = true,
})
override

Sets the values of all controls from the provided map val.

Implementation

@override
void setValue(Map<String, dynamic> val, {bool notify = true}) {
  for (final entry in val.entries) {
    final key = entry.key;
    if (!controls.containsKey(key)) continue;

    final ctrl = controls[key]!;
    var value = entry.value;

    if (ctrl is FormGroup) {
      if (value is Map<String, dynamic>) {
        ctrl.setValue(value, notify: notify);
        continue;
      }
      if (value == null) {
        ctrl.setValue(<String, dynamic>{}, notify: notify);
        continue;
      }
      throw ArgumentError(
        'Valor para "$key" precisa ser Map<String, dynamic> (FormGroup). '
            'Recebido: ${value.runtimeType}',
      );
    }

    ctrl.setValue(value, notify: notify);
  }

  if (notify) notifyListeners();
}