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
UnimplementedErrorwith a clear message. This lets test mocks stub only what they exercise.
- Inheritance
-
- Object
- PlatformInterface
- NsfwPlatformInterface
- Implementers
Constructors
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
-
addAssetsToAlbum(
List< String> localIdentifiers, String albumId) → Future<void> - Add assets to an album. See NsfwDetector.addAssetsToAlbum.
-
availableModels(
) → Future< List< ModelDescriptor> > -
cachedResult(
String localIdentifier, {String? modelId}) → Future< Map?> -
Look up a cached scan record for
localIdentifierwithout triggering a re-scan. Returns the wire-shape map (mirrors scanSingleAsset) when a row exists, ornullon 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.
-
createAlbum(
String title) → Future< String> - Create an album, returning its new local identifier.
-
deleteAssets(
List< String> localIdentifiers) → Future<bool> -
Delete assets (OS shows its own confirmation). Returns
truewhen the user confirmed,falsewhen they cancelled. See NsfwDetector.deleteAssets. -
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.
-
listAlbums(
) → Future< List< Map> > -
List user albums as
{id, title, count, isUserAlbum}maps. -
listAssetIdentifiers(
{String mediaType = 'image', int? limit}) → Future< List< String> > -
Enumerate photo-library asset identifiers (creationDate desc), so a
Dart-driven batch ensemble scan can iterate them.
mediaTypeis'image'(default),'video', or'any';limitcaps the count (0/null = all). Default throws. -
loadThumbnail(
String localIdentifier, {int maxWidth = 256, int maxHeight = 256}) → Future< Uint8List?> -
Load a downscaled thumbnail (JPEG bytes) for the photo-library asset
identified by
localIdentifier. Returnsnullwhen the asset cannot be resolved or decoded.maxWidth/maxHeightare an upper bound in logical pixels; aspect ratio is preserved. Default throws. -
moveAssetsToAlbum(
List< String> localIdentifiers, String toAlbumId, {String? fromAlbumId}) → Future<void> -
Move assets to
toAlbumId(add), optionally removing them fromfromAlbumId. See NsfwDetector.moveAssetsToAlbum. -
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< detections, required String mode, required double intensity, String? outputFormat}) → Future<String, Object?> >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< detections, required String mode, required double intensity, String? outputPath}) → Future<String, Object?> >String> -
Redact an image file on disk.
outputPathwhen 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.
-
removeAssetsFromAlbum(
List< String> localIdentifiers, String albumId) → Future<void> - Remove assets from an album. See NsfwDetector.removeAssetsFromAlbum.
-
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.
roiis 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
roicontract. -
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
BackgroundSweepOptionsdocs). -
setAssetFavorite(
String localIdentifier, bool favorite) → Future< void> - Toggle the favorite flag on the asset. See NsfwDetector.setAssetFavorite.
-
setAssetHidden(
String localIdentifier, ) → Future< void> - Toggle the hidden flag on the asset. See NsfwDetector.setAssetHidden.
-
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