unfocus method

void unfocus({
  1. bool touched = true,
})

Remove the focus from the UI widget without the interaction of the user.

The touched argument can be optionally provided. If touched is false then the control is marked as untouched and validations messages don't show up. If touched is true (default) the control is marked as touched and validation error messages comes visible in the UI.

Example:

Removes focus from a control

final formControl = form.formControl('name');

// UI text field lose focus
formControl.unfocus();

Removes focus to all children controls in a form

form.unfocus();

Removes focus to all children controls in an array

array.unfocus();

Implementation

void unfocus({bool touched = true}) {
  if (!touched) {
    markAsUntouched(emitEvent: false);
  }

  forEachChild((control) {
    control.unfocus(touched: touched);
  });
}