validateForm method

void validateForm({
  1. VoidCallback? onSuccess,
})

Validate the enclosing Form

Implementation

void validateForm({VoidCallback? onSuccess}) {
  // Clear current focus
  clearFocus();

  // Find closest Form ancestor
  // Throw if no Form ancestor is found
  final form = Form.of(this);

  // Validate form
  if (form.validate()) {
    form.save();
    onSuccess?.call();
  }
}