validate method

TValue? validate({
  1. bool autoUnfocus = true,
})

Validate all forms placed under Form to which key is passed, and if there are no problems, onSaved is executed and the value is returned.

If the validation is problematic, null is returned.

The onSaved is only executed if a value is returned.

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

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

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

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

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

Implementation

TValue? validate({bool autoUnfocus = true}) {
  if (autoUnfocus) {
    FocusManager.instance.primaryFocus?.unfocus();
  }
  if (key.currentState == null) {
    if (!_validate()) {
      return null;
    }
    _save();
    return value;
  }
  if (!key.currentState!.validate()) {
    return null;
  }
  key.currentState!.save();
  return value;
}