validate method
This validator type supports asynchronous validation
It might come useful e.g. if you need to make some backend validation of
the data entered into your form. With this validator
you don't have to invent a custom approach to validate anything. Just
do all of your asynchronous work inside the validator's body and
then return the result.
returns
Returns an error text if the validation fails.
If it returns null then the validation is successful
Implementation
@override
FutureOr<String?> validate(
Object? value, {
String? fieldName,
}) async {
if (value is List) {
for (var file in value) {
if (file is LiteFile) {
final LiteFile liteFile = file;
final kb = await liteFile.kiloBytes;
if (kb > maxSize.totalKilobytes) {
return 'Some file exceeds the maximum size of ${maxSize.toString()}, actual size is ${kb.kilobytesToLabel()}';
}
}
}
} else if (value is LiteFile) {
final LiteFile liteFile = value;
final kb = await liteFile.kiloBytes;
if (kb > maxSize.totalKilobytes) {
return 'Some file exceeds the maximum size of ${maxSize.toString()}, actual size is ${kb.kilobytesToLabel()}';
}
}
return null;
}