validate method

String? validate(
  1. List<PrismPickedFile> files
)

Returns a human-readable reason when files violate the constraints, or null when they are all acceptable.

Implementation

String? validate(List<PrismPickedFile> files) {
  if (maxFiles != null && files.length > maxFiles!) {
    return 'Pick at most $maxFiles file(s)';
  }
  for (final file in files) {
    if (allowedExtensions != null &&
        allowedExtensions!.isNotEmpty &&
        !allowedExtensions!.contains(file.extension)) {
      return '"${file.name}" is not an allowed type '
          '(${allowedExtensions!.join(', ')})';
    }
    if (maxSizeBytes != null && file.sizeBytes > maxSizeBytes!) {
      return '"${file.name}" is larger than the '
          '${_human(maxSizeBytes!)} limit';
    }
  }
  return null;
}