flutter_nude_detector 0.0.4 copy "flutter_nude_detector: ^0.0.4" to clipboard
flutter_nude_detector: ^0.0.4 copied to clipboard

flutter_nudity_detection is a comprehensive Flutter package that enables developers to detect nudity content in images with ease. It leverages the power of advanced machine learning algorithms to accu [...]

example/lib/main.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_nude_detector/flutter_nude_detector.dart';
import 'package:image_picker/image_picker.dart';

void main() => runApp(const MaterialApp(home: App()));

/// Main view of flutter_nude_detector example
class App extends StatefulWidget {
  /// App constructor
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  String? _imagePath;
  bool _containsNudity = false;

  Future<dynamic> _onButtonPressed() async {
    final image = await ImagePicker().pickImage(
      source: ImageSource.gallery,
      imageQuality: 100,
    );

    if (image != null) {
      final hasNudity = await FlutterNudeDetector.detect(path: image.path);
      setState(() {
        _imagePath = image.path;
        _containsNudity = hasNudity;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: _imagePath == null
            ? const Text('No image has been selected')
            : Stack(
          alignment: Alignment.center,
          children: [
            Image.file(File(_imagePath!)),
            NudityStatusChip(containsNudity: _containsNudity),
          ],
        ),
      ),
      bottomNavigationBar: SafeArea(
        child: ElevatedButton(
          onPressed: _onButtonPressed,
          child: const Padding(
            padding: EdgeInsets.symmetric(vertical: 24),
            child: Text('Open gallery'),
          ),
        ),
      ),
    );
  }
}

/// Widget chip that's shows nudity status
class NudityStatusChip extends StatelessWidget {
  /// NudityStatusChip constructor
  const NudityStatusChip({required this.containsNudity, super.key});

  /// Variable that indicate if image contains nudity or not
  final bool containsNudity;

  @override
  Widget build(BuildContext context) {
    return DecoratedBox(
      decoration: BoxDecoration(
        color: containsNudity ? Colors.red : Colors.green,
        borderRadius: const BorderRadius.all(
          Radius.circular(
            32,
          ),
        ),
      ),
      child: Padding(
        padding: const EdgeInsets.symmetric(
          horizontal: 16,
          vertical: 8,
        ),
        child: Text(
          containsNudity ? 'Contains nudity!' : 'Does not contain nudity',
          style: const TextStyle(
            color: Colors.white,
            fontSize: 16,
            fontWeight: FontWeight.w500,
          ),
        ),
      ),
    );
  }
}
29
likes
140
points
15
downloads

Publisher

unverified uploader

Weekly Downloads

flutter_nudity_detection is a comprehensive Flutter package that enables developers to detect nudity content in images with ease. It leverages the power of advanced machine learning algorithms to accurately identify and flag explicit or adult content within images, ensuring a safer and more secure user experience.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, google_mlkit_image_labeling, path, path_provider

More

Packages that depend on flutter_nude_detector