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

discontinued
outdated

nsfw detector nsfw image detector nsfw video detector nsfw detection NSFW Detection NSFW Detector NSFW Image Detector NSFW Video Detector NSFW video NSFW image NSFW detector

example/lib/main.dart

import 'dart:async';
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_nsfw/flutter_nsfw.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    Directory appDocDir = await getApplicationDocumentsDirectory();
    String appDocPath = appDocDir.path;
    var file = File(appDocPath + "/nsfw.tflite");
    if (!file.existsSync()) {
      var data = await rootBundle.load("assets/nsfw.tflite");
      final buffer = data.buffer;
      await file.writeAsBytes(
          buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
    }
    await FlutterNsfw.initNsfw(file.path);
  }

  String imgPath = "";

  double result = 0.0;
  bool _isNSFW = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              if (imgPath.isNotEmpty)
                Center(
                    child: Image.file(
                  File(imgPath),
                  width: 300,
                  height: 300,
                  fit: BoxFit.cover,
                )),
              Text('The result is : $result'),
              ElevatedButton(
                child: Text('Pick image'),
                onPressed: () async {
                  final ImagePicker _picker = ImagePicker();
                  final XFile? image =
                      await _picker.pickImage(source: ImageSource.gallery);
                  if (image != null) {
                    setState(() {
                      imgPath = image.path;
                    });
                    var score = await FlutterNsfw.getPhotoNSFWScore(imgPath);
                    setState(() {
                      result = score;
                    });
                  }
                },
              ),
              Text('The video is $_isNSFW'),
              ElevatedButton(
                child: Text('Pick Video'),
                onPressed: () async {
                  final ImagePicker _picker = ImagePicker();
                  final XFile? image =
                      await _picker.pickVideo(source: ImageSource.gallery);
                  if (image != null) {
                    String videoPath = '';
                    setState(() {
                      videoPath = image.path;
                    });
                    bool isNSFW = await FlutterNsfw.detectNSFWVideo(
                        videoPath: videoPath, nsfwThreshold: 0.9);
                    setState(() {
                      _isNSFW = isNSFW;
                    });
                  }
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
16
likes
0
pub points
51%
popularity

Publisher

verified publisherahsanali.xyz

nsfw detector nsfw image detector nsfw video detector nsfw detection NSFW Detection NSFW Detector NSFW Image Detector NSFW Video Detector NSFW video NSFW image NSFW detector

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_nsfw