imageOnly<E> static method
Validates that the file is an image.
Checks for common image extensions and MIME types.
FileRules.imageOnly(error: 'Only images allowed')
Implementation
static Rule<FileInfo, E> imageOnly<E>({required E error}) {
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'];
return PredicateRule(
predicate: (value) {
if (value.mimeType != null) {
return value.mimeType!.startsWith('image/');
}
return imageExtensions.contains(value.extension);
},
error: error,
);
}