revalidate method

void revalidate(
  1. BuildContext context,
  2. FormValidationMode state
)

Revalidates all form fields with validators.

Runs validation on all registered fields and updates their validation states. Supports both synchronous and asynchronous validators.

Parameters:

  • context (BuildContext, required): The build context.
  • state (FormValidationMode, required): Validation mode to use.

Implementation

void revalidate(BuildContext context, FormValidationMode state) {
  bool changed = false;
  for (var entry in _attachedInputs.entries) {
    var key = entry.key;
    var value = entry.value;
    if (value.validator != null) {
      var future = value.validator!.validate(context, value.value, state);
      if (_validity[key]?.result != future) {
        if (future is Future<ValidationResult?>) {
          _validity[key] = _ValidatorResultStash(future, state);
          future.then((value) {
            if (_validity[key]?.result == future) {
              _validity[key] =
                  _ValidatorResultStash(value?.attach(key), state);
              WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
                if (_disposed) {
                  return;
                }
                notifyListeners();
              });
            }
          });
        } else {
          _validity[key] = _ValidatorResultStash(future, state);
        }
        changed = true;
      }
    }
  }
  if (changed) {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      if (_disposed) {
        return;
      }
      notifyListeners();
    });
  }
}