validateAndSave method

  1. @Deprecated("Use validate instead. This method will be removed in the next major version.")
bool validateAndSave({
  1. bool autoUnfocus = true,
})

Validation is performed on all forms placed under Form to which key is passed, and if there are no problems, onSaved is executed.

If the validation is problematic, false is returned.

The onSaved is only executed if true is returned.

If autoUnfocus is true, the focus on the form is released.

keyを渡したFormの配下に置かれているすべてのフォームでバリデーションを行ない、問題なければonSavedが実行されます。

バリデーションが問題ある場合はfalseが返されます。

onSavedが実行されるのはtrueが返される場合のみです。

autoUnfocustrueの場合、フォームにあるフォーカスが解除されます。

Implementation

@Deprecated(
  "Use validate instead. This method will be removed in the next major version.",
)
bool validateAndSave({bool autoUnfocus = true}) {
  if (autoUnfocus) {
    FocusManager.instance.primaryFocus?.unfocus();
  }
  if (key.currentState == null) {
    if (!_validate()) {
      return false;
    }
    _save();
    return true;
  }
  if (!key.currentState!.validate()) {
    return false;
  }
  key.currentState!.save();
  return true;
}