validate method
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
が実行されるのは値が返される場合のみです。
autoUnfocus
がtrue
の場合、フォームにあるフォーカスが解除されます。
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;
}