validateFile static method
Validate file before upload
Implementation
static bool validateFile({
required File file,
int? maxSizeInBytes,
List<String>? allowedExtensions,
}) {
// Check if file exists
if (!file.existsSync()) return false;
// Check file size
if (maxSizeInBytes != null) {
if (file.lengthSync() > maxSizeInBytes) return false;
}
// Check file extension
if (allowedExtensions != null && allowedExtensions.isNotEmpty) {
final extension = file.path.split('.').last.toLowerCase();
if (!allowedExtensions.contains(extension)) return false;
}
return true;
}