validate method

void validate()

Get called each time that user entered a character in EditText

Implementation

void validate() {
  /// For each condition we called validators and get their new state
  _hasMinLength = _conditionsHelper.checkCondition(
      widget.minLength,
      _validator.hasMinLength,
      widget.controller,
      widget.translatedStrings.atLeast,
      _hasMinLength);

  _hasMinNormalChar = _conditionsHelper.checkCondition(
      widget.normalCharCount,
      _validator.hasMinNormalChar,
      widget.controller,
      widget.translatedStrings.normalLetters,
      _hasMinNormalChar);

  _hasMinUppercaseChar = _conditionsHelper.checkCondition(
      widget.uppercaseCharCount,
      _validator.hasMinUppercase,
      widget.controller,
      widget.translatedStrings.uppercaseLetters,
      _hasMinUppercaseChar);

  _hasMinLowercaseChar = _conditionsHelper.checkCondition(
      widget.lowercaseCharCount,
      _validator.hasMinLowercase,
      widget.controller,
      widget.translatedStrings.lowercaseLetters,
      _hasMinLowercaseChar);

  _hasMinNumericChar = _conditionsHelper.checkCondition(
      widget.numericCharCount,
      _validator.hasMinNumericChar,
      widget.controller,
      widget.translatedStrings.numericCharacters,
      _hasMinNumericChar);

  _hasMinSpecialChar = _conditionsHelper.checkCondition(
      widget.specialCharCount,
      _validator.hasMinSpecialChar,
      widget.controller,
      widget.translatedStrings.specialCharacters,
      _hasMinSpecialChar);

  /// Checks if all condition are true then call the onSuccess and if not, calls onFail method
  int conditionsCount = _conditionsHelper.getter()!.length;
  int trueCondition = 0;
  for (bool value in _conditionsHelper.getter()!.values) {
    if (value == true) trueCondition += 1;
  }
  if (conditionsCount == trueCondition)
    widget.onSuccess();
  else if (widget.onFail != null) widget.onFail!();

  //To prevent from calling the setState() after dispose()
  if (!mounted) return;

  //Rebuild the UI
  setState(() => null);
  trueCondition = 0;
}