handle method
Handle the validation, the info
variable will contain the following:
info'rule'
= Validation rule i.e "min".
info'data'
= Data the user has passed into the validation.
info'message'
= Overriding message to be displayed for validation (optional).
Implementation
@override
bool handle(Map<String, dynamic> info) {
RegExp regExp = RegExp(signature + r':([0-9]+)');
String match = regExp.firstMatch(info['rule'])?.group(1) ?? "";
int intMatch = int.parse(match);
description = "The $attribute must be older than $intMatch years old.";
textFieldMessage = "Must be older than $intMatch years old.";
super.handle(info);
dynamic date = info['data'];
if (date is String) {
DateTime? dateParsed = DateTime.tryParse(date);
if (dateParsed == null) {
NyLogger.error('Date is not valid');
return false;
}
return dateParsed.isAgeOlder(intMatch) ?? false;
}
if (date is DateTime) {
return date.isAgeOlder(intMatch) ?? false;
}
return false;
}