documentOnly<E> static method

Rule<FileInfo, E> documentOnly<E>({
  1. required E error,
})

Validates that the file is a document.

Checks for common document extensions.

FileRules.documentOnly(error: 'Only documents allowed')

Implementation

static Rule<FileInfo, E> documentOnly<E>({required E error}) {
  const docExtensions = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'rtf'];
  return PredicateRule(
    predicate: (value) {
      if (value.mimeType != null) {
        return value.mimeType!.startsWith('application/') ||
            value.mimeType == 'text/plain';
      }
      return docExtensions.contains(value.extension);
    },
    error: error,
  );
}