setErrors method

void setErrors(
  1. Map<String, dynamic> errors, {
  2. bool emitEvent = true,
})

Sets errors on a control.

This is used when validations are run not automatically, but manually by the user.

Calling setErrors will also update the validity of the parent control.

Usage

Control login = new Control("someLogin");
login.setErrors({
  "notUnique": true
});

expect(login.valid).toEqual(false);
expect(login.errors).toEqual({"notUnique": true});

login.updateValue("someOtherLogin");

expect(login.valid).toEqual(true);

Implementation

void setErrors(Map<String, dynamic> errors, {bool emitEvent = true}) {
  _errors = errors;
  _status = _calculateStatus();
  if (emitEvent) {
    _statusChanges.add(_status!);
  }
  _parent?._updateControlsErrors();
  // If a control's errors were specifically set then mark the control as
  // changed.
  markAsDirty(emitEvent: false);
}