NsfwPlatformInterface class abstract

Platform-interface contract for nsfw_detect.

Methods are split into two groups:

  • Lifecycle / critical (abstract — every implementation must provide them): permission, model listing, scan lifecycle, single-asset scan, and the raw event stream. Without these the plugin cannot function.
  • Optional / feature (default impls below): model download, custom URL, logging, cache, picker, file/bytes scanning. Default impls either return safely-ignored values or throw a UnimplementedError with a clear message. This lets test mocks stub only what they exercise.
Inheritance
  • Object
  • PlatformInterface
  • NsfwPlatformInterface
Implementers

Constructors

NsfwPlatformInterface()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scanEventStream Stream<Map>
no setter

Methods

availableModels() Future<List<ModelDescriptor>>
cachedResult(String localIdentifier, {String? modelId}) Future<Map?>
Look up a cached scan record for localIdentifier without triggering a re-scan. Returns the wire-shape map (mirrors scanSingleAsset) when a row exists, or null on miss. Default throws.
cancelBackgroundSweep() Future<void>
Cancel any pending background sweep. Default no-op — safe to call even if none was scheduled.
cancelScan() Future<void>
checkCameraPermission() Future<PermissionStatus>
checkPermission() Future<PhotoLibraryPermissionStatus>
checkPlatformSetup() Future<PlatformSetupReport>
clearScanCache({String? modelId}) Future<void>
Clear the persistent scan-result cache. Default no-op.
deleteModel(String modelId) Future<void>
Delete a previously-downloaded model. Default no-op.
downloadModel(String modelId, {String? url}) Future<bool>
Download a downloadable model. Default throws.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pickMedia({required String type, required bool multiple, int? maxItems}) Future<List<Map>>
Pure media picker (no classification). Default throws.
prefetchAssets(List<String> localIdentifiers, {String? modelId}) Future<void>
Pre-warm the native asset cache for the given local identifiers so the next scanSingleAsset or library scan can decode them with less I/O pressure. Default no-op — platforms without a meaningful warm-cache implementation just return.
preloadModel(String modelId) Future<void>
Compile / warm the model. Default no-op so test mocks don't need to stub.
redactBytes({required Uint8List bytes, required List<Map<String, Object?>> detections, required String mode, required double intensity, String? outputFormat}) Future<Uint8List>
Redact the supplied image bytes against the given detection list. Mode strings: "blur", "pixelate", "blackBox". Default throws.
redactFile({required String inputPath, required List<Map<String, Object?>> detections, required String mode, required double intensity, String? outputPath}) Future<String>
Redact an image file on disk. outputPath when null writes to a sibling temporary file. Returns the on-disk path of the redacted output. Default throws.
registerModel(Map<String, Object?> registration) Future<String>
Register a custom model descriptor at runtime. Returns the resolved asset path the native side will load from. Default throws.
requestCameraPermission() Future<PermissionStatus>
requestPermission() Future<PhotoLibraryPermissionStatus>
resetScan() Future<void>
Reset scan state (clears native checkpoints, etc.). Default no-op.
scanFilePath(String filePath, {String? modelId, Map<String, double>? roi}) Future<Map>
Scan an image file from path. Default throws. roi is a normalised {x, y, width, height} map in [0, 1]; native implementations that don't support cropping should ignore the key.
scanImageBytes(Uint8List bytes, {String? modelId, Map<String, double>? roi}) Future<Map>
Scan raw image bytes. Default throws. See scanFilePath for the roi contract.
scanSingleAsset(String localIdentifier, {String? modelId, Map<String, double>? roi}) Future<Map>
scheduleBackgroundSweep(Map<String, Object?> options) Future<void>
Schedule a recurring background scan. Default throws — host-app integration is required (Info.plist on iOS, WorkManager classpath on Android — see BackgroundSweepOptions docs).
setLogging(bool enabled) Future<void>
Toggle native logging. Default no-op.
setModelUrl(String modelId, String url) Future<void>
Set a custom download URL for a model. Default no-op.
skipCurrentAsset() Future<void>
Signal the native scan loop to skip the next asset it would process. Best-effort: one outstanding skip is consumed by the next per-asset task that checks the flag. No effect when no scan is running.
startCameraScan(CameraConfiguration config) Future<void>
startPickAndScan(ScanConfiguration config, int maxItems) Future<void>
Picker scan. Default throws — enable by overriding in your native impl.
startScan(ScanConfiguration config) Future<void>
stopCameraScan() Future<void>
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance NsfwPlatformInterface
getter/setter pair