make method
Implementation
ValidatorX make(List<dynamic> rules,
{String? attribute, Map<String, String>? customMessages}) {
final joinedRules = [
...numericRules,
...sizeRules,
...implicitRules,
...stringRules,
...others
];
return (String? value) {
assert(rules.contains("required"),
"You cannot validate a field that is not required. You can include the required rule in your list of rules for validation to work");
String? validationMessage;
for (var rule in rules) {
if (validationMessage != null) return validationMessage;
if (rule is FormFieldValidator<String?>) {
return rule.call(value);
}
if (rule is String) {
final _rule = rule.split(":")[0];
assert(joinedRules.contains(_rule),
"$rule is not a defined rule kindly check for spellings or error");
validationMessage = _validate(
_rule,
value!,
rule.split(":").length > 1 ? rule.split(":")[1] : null,
attribute,
customMessages != null ? customMessages[_rule] : null,
);
}
// else {
// final _rule = rule as RuleProtocol;
// new _rule();
// final instance = _rule.instance;
// validationMessage = instance.tryValidate();
// }
}
return validationMessage;
};
}