LengthValidator function
Implementation
TextValidator LengthValidator({int maxLength = 256, int minLength = 0, bool allowEmpty = true, bool trim = false, String? message}) {
String msg = message ?? "长度介于$minLength和$maxLength之间";
String? validator(String? text) {
if (text == null || text.isEmpty) return allowEmpty ? null : msg;
String s = trim ? text.trim() : text;
if (s.length < minLength) return msg;
if (s.length > maxLength) return msg;
return null;
}
return validator;
}