test method
Tests value against defined validations
Implementation
String? test(String? value) {
for (var validate in validations) {
// Return null if field is optional and value is null
if (optional && (value == null || value.isEmpty)) {
return null;
}
// Otherwise execute validations
final result = validate(value);
if (result != null) {
if (onValidationFailed != null) {
onValidationFailed!(); // Run the provided function
}
return result;
}
}
return null;
}