nsfw_detect 2.1.2
nsfw_detect: ^2.1.2 copied to clipboard
Privacy-friendly NSFW detection for Flutter apps. Analyze images, videos, picked media, photo libraries, and camera frames on-device.
nsfw_detect #
Privacy-friendly NSFW detection for Flutter apps, running fully on-device.
Use nsfw_detect to scan images, videos, selected media, photo libraries, and camera frames locally with Core ML on iOS and TensorFlow Lite on Android.
Detection is probabilistic. Use it as a local moderation signal and one layer in a broader safety workflow.
Features #
- On-device NSFW detection for Flutter apps
- Image, video, photo library, native picker, file, bytes, and camera scanning
- iOS support via Core ML and Vision
- Android support via TensorFlow Lite
- Stream-based scan results and progress updates
- Configurable confidence thresholds and model selection
- Classification categories: safe, suggestive, nudity, explicit nudity, unknown
- Optional detection mode with body-part bounding boxes
- Incremental scan cache for large media libraries
- Ready-to-use widgets and headless Dart APIs
- No telemetry or automatic media transmission by the plugin
Installation #
dependencies:
nsfw_detect: ^2.1.1
Then run:
flutter pub get
Platform requirements #
| Platform | Minimum |
|---|---|
| iOS | 16.0+ |
| Android | API 24 / Android 7.0+ |
| Flutter | 3.22+ |
| Dart | 3.4+ |
| Xcode | 15+ |
Quickstart #
Pick the entry point that matches your use case. All three run fully on-device.
1. pickMedia — easiest, no library permission #
Opens the system picker, scans only what the user selected. Because the picker grants per-item access, you do not need full photo-library permission.
import 'package:nsfw_detect/nsfw_detect.dart';
final picked = await NsfwDetector.instance.pickMedia(
type: MediaPickerType.any, // image | video | any
multiple: true,
maxItems: 5,
);
for (final item in picked) {
final result = await NsfwDetector.instance.scanAsset(
item.localId,
confidenceThreshold: 0.75,
);
if (result.isNsfw) {
// Block, blur, or route to review.
}
}
Prefer pickAndScan if you want the picker and the scan in a single streamed call:
final session = await NsfwDetector.instance.pickAndScan(maxItems: 5);
session.results.listen((r) { if (r.isNsfw) { /* ... */ } });
await session.done;
2. scanFile / scanBytes — already have the media #
Use these when your app already has a file path or raw bytes (captures, downloads, clipboard, generated images). No permission, no picker.
// From a path on disk
final result = await NsfwDetector.instance.scanFile(
'/path/to/image.jpg',
confidenceThreshold: 0.75,
);
if (result.isNsfw) {
// Keep it local and show a policy message.
}
// From bytes in memory (Uint8List)
final fromBytes = await NsfwDetector.instance.scanBytes(imageBytes);
3. startScan — full photo library scan #
Use this only when you want to scan a user's whole library. Requires photo-library permission.
final status = await NsfwDetector.instance.requestPermission();
if (status != PhotoLibraryPermissionStatus.authorized &&
status != PhotoLibraryPermissionStatus.limited) {
return; // Show your permission UI / fallback.
}
final session = await NsfwDetector.instance.startScan(
const ScanConfiguration(
confidenceThreshold: 0.75,
includeVideos: true,
maxVideoFrames: 8,
),
);
session.results.listen((r) { if (r.isNsfw) { /* ... */ } });
session.progress.listen((p) => debugPrint('${p.scannedCount}/${p.totalCount}'));
final summary = await session.done;
For camera scans, configuration details, and model handling, see the guides below.
Documentation #
- Getting started
- Permissions
- Media precheck
- Picker workflows
- Library scanning
- Camera scanning
- Configuration
- Models
- Privacy and limitations
- Troubleshooting
API reference is available on pub.dev.
Example app #
Run the example app from the repository:
git clone https://github.com/nexas105/flutter_nsfw_scaner.git
cd flutter_nsfw_scaner/example
flutter pub get
flutter run
A real iOS or Android device is recommended for photo library and camera workflows. The example app demonstrates gallery scanning, headless API usage, result detail screens, model selection, confidence thresholds, and video frame options.
Privacy #
nsfw_detect is designed for local-first media analysis.
- Inference runs on-device
- Inference runs in the native iOS and Android layers
- The plugin does not include analytics or telemetry
- Picker-based scanning can avoid full photo-library permission
Your app is still responsible for explaining permissions, handling results, storing any moderation state, and complying with platform, privacy, and safety requirements.
Limitations #
NSFW detection is probabilistic. Results can include false positives and false negatives, especially with unusual lighting, partial visibility, illustrations, screenshots, low-resolution media, compressed videos, or ambiguous content.
Tune confidence thresholds for your product risk. For sensitive workflows, combine on-device detection with user reporting, human review, policy-specific rules, or other moderation layers.
Package links #
License #
MIT. See LICENSE.