submitForm method
Submits the form and triggers validation.
Returns a SubmissionResult with form values and any validation errors. May return a Future if asynchronous validation is in progress.
Implementation
FutureOr<SubmissionResult> submitForm() {
final formState = Data.maybeFind<FormState>(this);
assert(formState != null, 'Form not found');
final formController = Data.maybeFind<FormController>(this);
assert(formController != null, 'Form not found');
final values = <FormKey, Object?>{};
for (var entry in formController!._attachedInputs.entries) {
var key = entry.key;
var value = entry.value;
values[key] = value.value;
}
formController.revalidate(this, FormValidationMode.submitted);
var errors = <FormKey, ValidationResult>{};
var iterator = formController._validity.entries.iterator;
var result = _chainedSubmitForm(values, errors, iterator);
if (result is Future<SubmissionResult>) {
return result.then((value) {
if (value.errors.isNotEmpty) {
return value;
}
formState?.widget.onSubmit?.call(this, values);
return value;
});
}
if (result.errors.isNotEmpty) {
return result;
}
formState?.widget.onSubmit?.call(this, values);
return result;
}