validate method

  1. @nonVirtual
String? validate({
  1. required AsyncValidator<T> validator,
  2. required T? value,
  3. required Locale locale,
  4. required AsyncValidationCompletionCallback onCompleted,
  5. required AsyncValidationFailureHandler failureHandler,
})

Validates specified value with specified AsyncValidator and Locale.

locale should be retrieved from BuildContext with appropriate way depends on localization framework which you use. Unfortunately, AsyncValidatorExecutor cannot guess your default locale.

onCompleted will be called when the validation will be done. The parameter is validation message, which will be null if there will be no validation errors. Note that this callback will be called when the validation is NOT completed with unexpected error. In the case, the error parameter will not be null, and the value of result parameter will be string representation of the error.

This method just calls execute.

Implementation

@nonVirtual
String? validate({
  required AsyncValidator<T> validator,
  required T? value,
  required Locale locale,
  required AsyncValidationCompletionCallback onCompleted,
  required AsyncValidationFailureHandler failureHandler,
}) =>
    execute(
      ValidationInvocation<T?>(
        validator: validator,
        value: value,
        locale: locale,
        onCompleted: (v) => onCompleted(v, null),
        onFailed: (e) => onCompleted(null, e),
        failureHandler: failureHandler,
      ),
    );