nsfw_detector_flutter 2.0.0 copy "nsfw_detector_flutter: ^2.0.0" to clipboard
nsfw_detector_flutter: ^2.0.0 copied to clipboard

A Flutter package to detect NSFW (Not Safe For Work / NUDE / adults) content and classify SAFE content without requiring assets. Easily integrate NSFW detection into your app.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:nsfw_detector_flutter/nsfw_detector_flutter.dart';
import 'package:flutter/services.dart';
import 'package:image/image.dart' as img;

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _result = "Loading...";

  @override
  void initState() {
    super.initState();
    _detectNSFW();
  }

  Future<void> _detectNSFW() async {
    try {
      // Load the image file
      final ByteData data = await rootBundle.load('assets/nsfw.jpeg');
      final Uint8List imageData = data.buffer.asUint8List();
      
      img.Image? image = img.decodeImage(imageData);
      if (image == null) {
        setState(() {
          _result = 'Failed to decode image.';
        });
        return;
      }

      // Load and initialize the NSFW detector
      NsfwDetector detector = await NsfwDetector.load();
      try {
        NsfwResult? result = await detector.detectNSFWFromImage(image);

        setState(() {
          _result = 'NSFW score: ${result?.score}, Detected: ${result?.isNsfw}';
        });
      } finally {
        detector.close();
      }
    } catch (e) {
      setState(() {
        _result = 'Error: $e';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('NSFW Detector Example'),
        ),
        body: Center(
          child: Text(_result),
        ),
      ),
    );
  }
}
15
likes
160
points
2.11k
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter package to detect NSFW (Not Safe For Work / NUDE / adults) content and classify SAFE content without requiring assets. Easily integrate NSFW detection into your app.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

cross_file, flutter, image, tflite_flutter

More

Packages that depend on nsfw_detector_flutter