detectNSFWFromXFile method
Detects NSFW content from an XFile.
Implementation
Future<NsfwResult?> detectNSFWFromXFile(XFile xfile) async {
if (_isClosed) throw StateError('NsfwDetector has been closed.');
try {
final imageData = await xfile.readAsBytes();
return await detectNSFWFromBytes(imageData);
} catch (error, stackTrace) {
if (error is NsfwDetectorException || error is ArgumentError) {
rethrow;
}
throw NsfwDetectorException(
'Failed to detect NSFW content from XFile: ${xfile.name}',
cause: error,
stackTrace: stackTrace,
);
}
}