fileExtensionValidator static method
fileExtensionValidator to validate a file path
validator: (value) => SimpleValidations.fileExtensionValidator(filePath, ['pdf', 'png'], [errorMessage]),
Implementation
static String? fileExtensionValidator(
String? value, List<String> allowedExtensions,
[String? errorMessage]) {
if (value == null || value.isEmpty) {
return errorMessage ?? 'Required';
}
String extension = value.split('.').last;
if (!allowedExtensions.contains(extension.toLowerCase())) {
return errorMessage ?? 'Invalid file extension';
}
return null;
}